views:

1147

answers:

4

How is it possible to set up a shared view script path for partials to create global partials within the Zend Framework?

We know that you can call partials between modules

e.g - echo $this->partial('partial_title','module_name');

but we need to set up a partial folder in the root ( i.e below modules) so that it can be accessble by all views.

It has been suggested to set up a shared view script path, how is this done?

+2  A: 

Zend_View has a method called addScriptPath, so in a Zend_Controller_Action subclass you could do something like:

$this->view->addScriptPath("/path/to/your/view/scripts/");

Now when you call render or partial or partialLoop, that path will be included in the paths.

Typeoneerror
A: 

Thanks for the response

Thanks for your response. It seems that due to a redirect plugin we are using for the modules, calling default in the partial call it searched outside of the modules

i.e >

( array( 'default' => self::$root . '/app/controllers', 'siteadmin' => self::$root . '/app/modules/siteadmin/controllers', 'myadmin' => self::$root . '/app/modules/myadmin/controllers', 'stats' => self::$root . '/app/modules/stats/controllers' ) );

Rhys Thought
A: 

I have a module and from inside the Controller, tried to call the partial but it doesn't work..

$message = $this->view->partial('templates/default.phtml'); 

Module Controller is executing and the result is displayed in the default (action specific) views.

Controller path:

application/modules/mymodule/IndexController.php

This is the partial file path:

application/modules/mymodule/views/scripts/templates/default.phtml

dremay
A: 

I have got a solution. We can do this by specifying the location of the view:

Calling partial as above form Module/Controller page

Method 1:

$this->view->addScriptPath("/ModuleConatinerDirectory/ModuleName/view/scripts/");

Then load using:

$message = $this->view->partial('templates/default.phtml','contact',array('var'=> 'var');

For the second option, please read the following:

http://framework.zend.com/issues/browse/ZF-6201

Now my doubt is, whether it is possible on setting it directly on Bootstrap file for all my Modules ? If so, how can I set this for two modules Module1 and Module2

$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' ); $viewRenderer->setViewBasePathSpec( '/some/absolute/path/to/templates/:module/' );

dremay