Moid Mohd Moid Mohd - 5 months ago 88
PHP Question

Change layout file within a view in Yii2

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

Inside the relative action

public function actionYourAction($id)
{


    $this->layout = 'yourNewLayout';

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