尝试为该模块使用不同的布局。首先,您可以将布局文件夹和布局文件添加到该模块,例如:/protected/modules/quiz/views/layouts/quizlayout.php。所以这个新的 quizlayout.php 应该是这个模块中所有视图的布局。
为此,您可以在 QuizModule 类的 init() 中设置 quizmodule 的 layout property,如下所示(在 QuizModule.php 中):
class QuizModule extends CWebModule {
public function init() {
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'quiz.models.*',
'quiz.components.*',
));
$this->layout='quizlayout';
}
//...
}
现在默认情况下,gii 生成的模块的控制器是 component/Controller.php 文件中Controller 类的子类。而那个Controller 类定义了一个layout,所以如果你有相同的结构,那么上面的方法将不起作用,你必须覆盖模块控制器中的布局。但是,您可以在 QuizModule.php 中的 beforeControllerAction($controller, $action) 函数中执行此操作,而不是进入每个控制器并添加一行:
public function beforeControllerAction($controller, $action) {
if(parent::beforeControllerAction($controller, $action)) {
// this method is called before any module controller action is performed
// you may place customized code here
$controller->layout='quizlayout';
return true;
}
else
return false;
}
编辑:
当然,您的 quizlayout.php 不应该有菜单代码和任何额外的东西,但至少应该有 echo $content 行,正如爱斯基摩人的回答中提到的那样。