Rakesh Shekhawat
Rakesh Shekhawat

Reputation: 358

How to create a different layout for admin controller in Phalcon?

Building an application in Phalcon, I am struggling for couple of hours to set the different layout for admin other than main layout.

My controller is AdminController, I have created a file views/layouts/admin.volt but I still see the main layout applied although I have set layout in initialize function of AdminController using $this->view->setLayout('admin');

Upvotes: 2

Views: 1552

Answers (1)

mcarra66
mcarra66

Reputation: 115

You need to remove your layout views/index.phtml and place it inside views/layouts/index.phtml

Then you can switch your layout from index to custom or any other using:

$layout = 'anonymous';

if ($this->session->has('user')) {
    $layout = 'index';
}

$this->view->setLayout($layout);

Phalcon loads in first place views/index.phtml, then it writes the content found in views/layouts/index.phtml (related to your controller) and finally it writes your views/index/index.phtml (related to your action HTML content)

Upvotes: 2

Related Questions