Davey
(Davey975)
January 31, 2014, 11:03am
1
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.
JFReyes
(Jose Reyes)
January 31, 2014, 11:53am
2
Inside the error action place this command to change the layout: $this->layout = ‘//layouts/errorlayout’ or whatever its name is.
Davey
(Davey975)
January 31, 2014, 12:56pm
3
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.
JFReyes
(Jose Reyes)
January 31, 2014, 1:09pm
4
Sorry, I didn’t notice it was posted under Yii2. I have to get on with it soon…
qiang
(Qiang Xue)
January 31, 2014, 5:09pm
5
In your error view, you can assign $this->context->layout = 'yourlayout';
kalempir
(Asanjarbek)
February 3, 2014, 5:34am
6
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.
Davey
(Davey975)
February 3, 2014, 9:09am
7
Both thanks for the solutions!