Choosing different views for module base Zend application
I have defined modules in my application using addModuleDirectory :
Application
|
modules
|
module1
|
module2
Now I want to set different views for each开发者_运维问答 module in my Bootstrap.php how to achieve this?
If what you want is a way to switch layout not views depending on the module, what you need is a standard front controller plugin.
A really simple implementation would be:
class LayoutModuleSwitcher extends \Zend_Controller_Plugin_Abstract
{
/**
* @param Zend_Controller_Request_Abstract Request object
*/
public function routeShutdown(\Zend_Controller_Request_Abstract $request)
{
\Zend_Layout::getMvcInstance()
->setLayoutPath(APPLICATION_PATH . '/layouts/' . $request->getModuleName() . '/scripts/');
}
}
While having the following layouts structure:
application/layouts/module1/scripts/layout.phtml
application/layouts/module2/scripts/layout.phtml
Depending on the following configuration:
resources.frontController.plugins.LayoutModuleSwitcher = "Ahp\Controller\Plugin\LayoutModuleSwitcher"
resources.layout.layout = "layout"; The name of your layout.phtml without the suffix, needed to init layout
精彩评论