Reputation: 6800
I have a question about layouts in Zend Framework. This is my structure of my project:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
Now how can I fix this that I have seperate layouts?
Upvotes: 5
Views: 5702
Reputation: 89
Put this into your application.ini
resources.layout.layout = "layout"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
Your layout file will be /modules/MODULE_NAME/views/scripts/layout.phtml
Upvotes: 3
Reputation: 171
I use this custom plugin with some changes, and for each module I create specific layout, with specific structure http://blog.vandenbos.org/2009/07/19/zend-framework-module-specific-layout/
Upvotes: 0
Reputation: 4898
You should write front controller plugin for that purpose (called layout selector).
In your Bootstrap.php register that plugin - layout selector:
protected function _initPlugins(){
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new My_Plugins_LayoutSelector());
}
Auto load namespace My_ in application.ini
Autoloadernamespaces[] = "My_"
And finally, create in /library a new folder 'My' and in it folder 'Plugins' and in it file 'LayoutSelector.php' with code:
class My_Plugins_LayoutSelector extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$module = $request->getModuleName();
$layout = Zend_Layout::getMvcInstance();
$layout->setLayout($module);
}
}
In this way every module in the future will use appropriate layout and no need to write in each controller to select layout.
Upvotes: 1
Reputation: 40675
Just place another layout in the layout/scripts
folder and tell any module, controller or action to use that other layout instead of the default layout.
If you want to let a controller use a different layout, you can place the following in your init()
$this->_helper->layout->setLayout('layoutname');
You can do that respectively for specific actions or for a whole module.
Upvotes: 8