Answer the question
In order to leave comments, you need to log in
How to load separate layout if Ajax request?
How can I load a separate layout if the server sends an Ajax request?
public function init()
{
parent::init();
if (Yii::$app->request->isAjax){
$this->layout = '/ajax_page';
}else{
$this->layout = '/blank-panel';
}
Answer the question
In order to leave comments, you need to log in
You are apparently trying to do it in a module (judging by init), and there inside $this is a module (which is logical). So what is needed in the controller in beforeAction:
public function beforeAction($action)
{
$this->layout = Yii::$app->request->isAjax ? '/ajax_page' : '/blank-panel';
return parent::beforeAction($action);
}
do you need layout or view? Usually, when using Ajax, the renderAjax() method is used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question