我在我的web項目中使用Yii框架。現在,我有幾個模塊,我只想爲所有模塊使用一個佈局。我已經使用以下代碼用於確定每個模塊中的每個控制器/動作的佈局:在Yii中使用幾個模塊的通用佈局
$this->layoutPath = Yii::getPathOfAlias('application.views.layouts');
$this->layout = '//layouts/myLayout';
是否有任何其他的解決方案,通過使用相同的碼在初始化每個模塊的()函數來做到這一點? 換句話說,我必須在每個動作中編寫上面的2行代碼,我認爲它不好,我想減少我的代碼行數。例如如下:
class StaffModule extends CWebModule
{
public $layout;
public $layoutPath;
public function init()
{
$this->layoutPath = Yii::getPathOfAlias('application.views.layouts');
$this->layout = '//layouts/myLayout';
$this->setImport(array(
'staff.models.*',
'staff.components.*',
));
}
}
但它不起作用。請幫幫我。