1
我試圖從字符串Yii::app()->user->id_rol
調用此方法。所以,我想要接這個字符串然後再打電話。從PHP中的字符串調用靜態方法
我試着這樣做:
$class = "Yii::app()->user->id_rol";
$class = explode('::',$class);
$class[1] = explode('->',$class[1]);
$class2 = new $class[0];
$string = "";
$n = count($class[1]);
for($i = 0; $i<$n;$i++){
(($i+1) == $n) ? $fl = '' : $fl = '->';
$string .= $class[1][$i].$fl;
}
$model = $class2->$string;
...但是,這是行不通的。
未定義的屬性:的Yii :: $應用程序() - >用戶> id_rol
我怎麼可能使它工作?
你究竟想要完成什麼,更大的圖片,在這裏? –
我試圖指定VAR名稱來接收rol id在我的新模塊參數,像這'評估'=>數組( \t \t'id_rol'=>'Yii :: app() - > user-> id_rol', \t \t), 所以,我需要把這個文字字符串作爲變量 –
'$ prop ='id_rol';警予::應用程序() - >用戶 - > $ prop'? – mnv