2012-10-24 24 views
1

我正在使用codeignighter。我怎樣才能得到在課堂上定義的變量,並將它用在別的地方

我有一個類,有一些變量,我需要使用別的地方。

例如:

class details{ 

public $username; 
public $current_uID; 
public $member_status; 

    public function __construct(){ 
     $this->username = 'username'; 
     $this->current_uID = 21; 
     $this->member_status = 1; 
    } 
} 

現在我的問題是我如何訪問這些變量 - 如果我這樣做,他們將在結構中定義的值?

+0

這比笨權更多的是與PHP類?只需創建該類的一個實例。 –

回答

0
$details = new details(); 

$username = $details->username; 
1

剛剛創建類,並使用創建的實例的屬性:

$details = new details(); 
echo $details->username; // will put 'username' on the screen 
相關問題