views:

164

answers:

1

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.

A: 

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");
Typeoneerror
works like a charm... unfortunately there is nothing to find about that in the web.I love this website really fast response and the quality of those are very good. Thanks again.Someday in future, when iam zend pro :) i will provide my help here too :)The second tip is really the good!
Oliver
@Oliver The Zend documentation is pretty fantastic. I found the same tutorial on the page on view controllers: http://framework.zend.com/manual/en/zend.view.controllers.html
Typeoneerror
@Oliver don't forget to vote my answer up and make it as the "best answer" if it helped you. That's how the site works :)
Typeoneerror