Change layout file within a view in Yii2

Moid Mohd picture Moid Mohd · May 1, 2015 · Viewed 32.1k times · Source

I am doing a small project using Yii2.

Suppose I have same layout (header, footer) in a view (eg site) except a login.php in this view. I want a different or no header / footer in this file. What can I do the remove the header / footer only from this view file.

All I could get to change layout in different views. Is it possible to change layout in a single file of a view?

Answer

scaisEdge picture scaisEdge · May 1, 2015

Inside the relative action:

public function actionYourAction($id)
{

    $this->layout = 'yourNewLayout';

    return $this->render('yourView', [
        'model' =>$model,
    ]);
}