1

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.

2
  • 1
    preDispatch should work fine. How were you trying to access the models and what error(s) did you get? Commented Nov 11, 2011 at 17:31
  • Turns out my main problem is routing, the model works in my preDispatch. I will post the routing question separately. Thanks! Commented Nov 20, 2011 at 18:34

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Pavel. As I wrote above, the main problem is routing. Once I figure that out I will try using a controller plugin as you suggest, looks good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.