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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:22:13  来源:igfitidea点击:

In Yii2, how can I exclude layout from rendering in a view file?

phpyii2

提问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

This can be done using renderPartial()method.

这可以使用renderPartial()方法来完成。

You can get more from the official documentation. Here's a link!

您可以从官方文档中获得更多信息。这是一个链接

回答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 renderPartialto exclude header and footer of layout from view file. However if you renderPartialit will not load asset files (css and js files). To load asset files without layout you can use renderAjax.

您可以使用renderPartial从视图文件中排除布局的页眉和页脚。但是,如果您renderPartial不会加载资产文件(css 和 js 文件)。要加载没有布局的资产文件,您可以使用renderAjax.