程序代碼
class SiteController extends CController
{
public $aboutLittle = null ; //定義一個屬性,一定要是public的,要不layout中訪問不到
public function actionIndex()
{
$this->aboutLittle = 123456 ;
}
}
在layout中調用則爲:
程序代碼<?php echo $this->aboutLittle?>
方法:
1 將data從控制器傳到視圖頁面,然後在引用layout的函數中,從renderPartial的第二個參數傳值給layout
2 在控制器裏定義類變量,在layout中用$this-> 來調用
3 使用Yii::app()->params['xyz'] 來傳值
4 做成 widget