2012-07-27 123 views
0

有没有人有指导或可以提供一个快速的例子如何设置一个类,并将数据从类传递到index.php?设置没有框架的PHP类

我在想我能做到这一点,就像我在一个框架中可以做到吗?

$this->class->function();

+1

我不明白你在问什么?传递什么样的数据? – 2012-07-27 21:36:27

+0

为了记录您可以(也应该)在文档中阅读很多内容:http://www.php.net/manual/en/language.oop5.basic.php – Mahn 2012-07-27 21:47:10

回答

4

coolclass.php

class coolClass 
{ 
    public function getPrintables() 
    { 
     return "hello world!"; 
    } 
} 

的index.php

include 'coolclass.php'; 
$instance = new coolClass(); 
echo $instance->getPrintables(); 
+0

谢谢,我在正确的轨道上 – 2012-07-27 21:39:39

1

一个简单的例子:

Foo.php

class Foo { 
    public __construct() { 
    ..initialize your variables here... 
    } 

    public function doSomething() { 
    ..have your function do something... 

    } 
} 

的index.php:

Include('Foo.php'); 
$my_Foo = Foo(); 
$my_Foo->doSomething(); 

我认为它相当直接的,以这里发生了什么...所以生病离开它。不想放弃太多。