2012-07-27 121 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(); 

我認爲它相當直接的,以這裏發生了什麼...所以生病離開它。不想放棄太多。