NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
1.在``views/layouts``下新建`common.php`文件 代码如下: ``` <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>hello common</h1> <?=$content;?> </body> </html> ``` $content表示被替换的内容 ***** 2.控制器里 ``` //指明用views/layouts/common.php作为布局文件 public $layout='common'; public function actionTestLayout(){ //视图会替换common.php里的$content return $this->render('test_layout'); } ``` 注意:控制器里用驼峰命令的方法,要用`-`连接访问,比如这样访问 `http://127.0.0.5/index.php?r=hello/test-layout`