php 在 Yii2 中,如何从视图文件中的渲染中排除布局?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29361782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Yii2, how can I exclude layout from rendering in a view file?
提问by learner
I have an admin login page that I want to render without the layout. How can I render a view in Yii2 without rendering the main layout?
我有一个管理员登录页面,我想在没有布局的情况下呈现。如何在不渲染主布局的情况下在 Yii2 中渲染视图?
回答by Zack
回答by user1852788
In your controller you can assing layout for all actions of controller or turn it off:
在您的控制器中,您可以为控制器的所有操作分配布局或将其关闭:
class AdminController extends Controller
{
// public $layout='//admin';
public $layout=false;
OR you can do it for only one action:
或者,您只能通过一项操作来执行此操作:
public function actionIndex()
{
$this->layout = false;
回答by Vinit Singh
You can use renderPartial
to exclude header and footer of layout from view file. However if you renderPartial
it will not load asset files (css and js files). To load asset files without layout you can use renderAjax
.
您可以使用renderPartial
从视图文件中排除布局的页眉和页脚。但是,如果您renderPartial
不会加载资产文件(css 和 js 文件)。要加载没有布局的资产文件,您可以使用renderAjax
.