Reputation: 117
I need to switch the layout based on a user value that is stored in the database. I would like to set this using a plugin (tried PreDispatch hook). However, it looks like I can't access the models there as yet. At what point can I access db values and set the layout? I prefer to do this globally rather than set for each controller. Ideas appreciated.
Upvotes: 1
Views: 263
Reputation: 119
For such purposes better to use controller plugin
class Core_Controller_Plugin_LayoutManager extends Zend_Controller_Plugin_Abstract
{
public function routeStartup (Zend_Controller_Request_Abstract $request)
{
// Get your layout name here
$this->_layout = Zend_Layout::getMvcInstance()
->setLayoutPath(YOUR_PATH_HERE)
->setLayout(YOUR_LAYOT_NAME_HERE);
}
}
Don't forget to add in in config:
resources.frontController.plugins.templatemanager = Core_Controller_Plugin_LayoutManager
Upvotes: 1