开发者

How to load view-Templates from default when not available in module? Zend Framework

开发者 https://www.devze.com 2022-12-23 19:38 出处:网络
Hi my problem with Zend Framework... unfortunately not solved after 3 hours of searching: I have a modular Zend Application, which is working fine if i have my module and error templates in the calle

Hi my problem with Zend Framework... unfortunately not solved after 3 hours of searching:

I have a modular Zend Application, which is working fine if i have my module and error templates in the called module. If i delete error/error.phtml out of views/scripts/ a Fatal Error is showing up that there is no directory.

To cut a long story short: How can i define that Zend falls back to default module in this situatio开发者_高级运维n?

Many thanks in advance.


When you render views, there's a sort of "stack" that the view renderer looks at for paths to your view scripts. The order that you add script paths to the view determines the look-up order. So:

$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH . "/default/views/scripts/")
     ->addScriptPath(APPLICATION_PATH . "/modules/module/views/scripts/");

In the above, it'll first look in "/modules...", then "/default...", and then it'll actually look for the view in the current directory the script is running in for your view script.

You can also add layout paths using the same method. One other tip that I found useful was changing the viewScriptPathSpec, which tells the view the file path to render:

$this->_helper->viewRenderer->setViewScriptPathSpec(":controller/:action.:suffix");

This is the default setting I believe, but you can change it if you like. For example, I have a CMS module that, no matter what the controller name is, it always renders the scripts in the "crud" view script folder:

$this->_helper->viewRenderer->setViewScriptPathSpec("crud/:action.:suffix");
0

精彩评论

暂无评论...
验证码 换一张
取 消