Is is possible to change the layout for the errorAction? I’m using different layouts depending whether the user is logged in or not, but in case there’s an error, i don’t want to use those layouts. I see there’s a $view property in the ErrorAction class, but no possibilty to change the layout.
Inside the error action place this command to change the layout: $this->layout = ‘//layouts/errorlayout’ or whatever its name is.
That would work in Yii 1.x, but the error action is no seperate action inside SiteController anymore in Yii 2, but a different class.
Sorry, I didn’t notice it was posted under Yii2. I have to get on with it soon… ![]()
In your error view, you can assign $this->context->layout = 'yourlayout';
I did it like this.
public function beforeAction($action)
{
if ($action->id == 'error')
$this->layout = 'iframe-main.php';
return parent::beforeAction($action);
}
But agree, qiang solution simpler.
Both thanks for the solutions!