1、在控制器中切换当前布局和在方法中动态切换布局
layout = "custom2";
$this->render('index',array(
'name' => '谭勇',
'age' => 22
));
}
}
?>在类属性中声明layout 会覆盖父类Controller 类中的layout 达到切换布局的目录。
甚至我们可以在模块文件中声明布局
namespace app\modules\TestModule;
use yii\base\Module;
class TestModule extends Module
{
//当前应用主题
private $theme = 'default';
public function init()
{
//控制器文件存放目录
$this->controllerNamespace = 'app\modules\TestModule\controllers';
$dirname = dirname(__FILE__);
//视图目录 (包含主题目录)
$this->setViewPath($dirname . '/views/' . $this->theme . '/');
//生命布局名称
$this->layout = "common";
}
}
上一篇:怎么在php中实现接口隔离