0

我有一个自定义模块,它使用它自己的一组布局/视图。但是对于错误,我想使用默认的站点布局和视图。在我的模块中,我errorHandler errorActionsite/error

class AdminModule extends CWebModule {

    public function init() {
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
        ));

        Yii::app()->setComponents(array(
            'errorHandler'=>array('errorAction'=>'site/error'),
        ));

        $this->layout = 'admin';
    }


    public function beforeControllerAction($controller, $action) {
        if(parent::beforeControllerAction($controller, $action)) {
            $controller->layout = $this->layout;
            return true;
        } else {
            return false;
        }
    }
}

但是它仍在使用管理布局,我希望它使用默认布局。如何仅针对错误操作覆盖它?

4

1 回答 1

1

在你actionError()SiteController只需添加默认布局名称

class SiteController extends Controller
{

public function actionError()
    {
        $this->layout='defaultLayoutName';
           //rest of the code goes here
    }
}
于 2013-02-01T09:17:54.097 回答