Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework: How do I change the default layout script to something other than layout.phtml?

I'd like to name my default layout file something other than layout.phtml, since it doesn't really describe what type of layout it is. How can I do this? Thanks!

like image 282
blacktie24 Avatar asked Jan 18 '23 13:01

blacktie24


1 Answers

From your Bootstrap.php file, you could do something like this:

protected function _initLayoutName()
{
    // use sitelayout.phtml as the main layout file
    Zend_Layout::getMvcInstance()->setLayout('sitelayout');
}

If you want to use a different layout for a different module, you need to register a plugin in the Bootstrap and have the plugin contain the following code:

class Application_Plugin_LayoutSwitcher extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName(); // get the name of the current module

        if ('admin' == $module) {
            // set the layout to admin.phtml if we are in admin module
            Zend_Layout::getMvcInstance()->setLayout('admin');
        } else if ('somethingelse' == $module) {
            Zend_Layout::getMvcInstance()->setLayout('somethingelse');
        }
    }
}

From within your application.ini, you can do this to set the layout script:

resources.layout.layout = "layoutname"

This will not work on a per layout basis, however. If you need to change the layout based on the module, you will have to use a plugin, but you can use the setting in application.ini to set the default layout name.

like image 172
drew010 Avatar answered Mar 01 '23 22:03

drew010