Oliver
Oliver

Reputation: 695

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

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 situation?

Many thanks in advance.

Upvotes: 0

Views: 1475

Answers (1)

typeoneerror
typeoneerror

Reputation: 56948

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");

Upvotes: 1

Related Questions