2014-10-03 71 views
0
<? 
var_dump($params); output is this: 
?> 

object(Cart)#20 (40) { 
["id"]=> 
int(117) 
["id_address_invoice"]=> 
string(2) "18" 
["id_currency"]=> 
    string(1) "1" 
    ["id_customer"]=> 
    string(6) "120883" 
    ["id_guest"]=> 
    string(1) "1" 
    ["id_lang"]=>.......... 

如何從上述對象中獲取「id_customer」?獲取對象的值

I`ve嘗試:

$params->cart->id_customer 

,但它是錯誤的。

+2

' - > cart'是錯誤的。該對象是CLASS'Cart'的對象,但是'cart'不是層次結構的一部分。 '$ params-> id_customer'是你所需要的。 – 2014-10-03 14:47:08

回答

0

$ params爲購物車對象,你不需要在你的訪問將其指定:

嘗試

$params->id_customer 

代替

0

嘗試沒有->cart

$params->id_customer 
0

你有類包括一些變量的購物車。看看例子,你明白。

class Cart{ 

     public $id = 117; 
     public $id_address_invoice = 18; 
     public $id_currency = 1; 
     public $id_customer = 18; 

    } 

    $param = new cart(); 

    var_dump($param); 
    var_dump($param->id); 
    var_dump($param->id_customer); 

結果:

object(Cart)#1 (4) { 
    ["id"]=> 
    int(117) 
    ["id_address_invoice"]=> 
    int(18) 
    ["id_currency"]=> 
    int(1) 
    ["id_customer"]=> 
    int(18) 
} 
int(117) //$id 
int(18) //id_customer 
0

您可以訪問類的車?請粘貼課程代碼。

也許存在一種方法getId_Costumer();在類中的方法獲得

搜索或類似

public function getId_Costumer() 
{ 
return this->id_customer; 
}