In Yii2, how can I exclude layout from rendering i

2019-04-20 19:32发布

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?

标签: php yii2
3条回答
Animai°情兽
2楼-- · 2019-04-20 20:15

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.

查看更多
叛逆
3楼-- · 2019-04-20 20:26

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;
查看更多
混吃等死
4楼-- · 2019-04-20 20:34

This can be done using renderPartial() method.

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

查看更多
登录 后发表回答