-- Martin Carpentier <[EMAIL PROTECTED]> wrote
(on Thursday, 29 March 2007, 02:48 PM +0200):
> I'm currently in the process of upgrading our application to ZF 0.9.1 from 0.8
> . So far it's going smoothly and I took the oportunity to convert to a
> Conventional Modular for convenience and because since the application is an
> intranet, it will eventually includes a lot of different modules.
> 
> So I based the directory structure on what's described here Conventional
> Modular Layout to have something that looks like this:
> 

<snip -- directory layout> 

> In the bootstrap I correctly set the controller directories with:
> 
> $controller = Zend_Controller_Front::getInstance();
> $controller->throwExceptions(true)
>                ->setControllerDirectory(array(
>                    'default' => '../application/default/controllers',
>                    '(module x)' => '../application/(module x)/controllers'))
>                ->setParam('config', $config);
> 
> 
> With that setup I can simply use this in the default controller:
> 
>     function init()
>     {
>         $this->initView();
>         $this->view->config = $this->getInvokeArg('config');
>         $this->view->baseUrl = $this->_request->getBaseUrl();
>     }
>    
>     function indexAction()
>     {
>         $this->view->title = 'title';
> 
>         $this->view->actionTemplate = '_menu.phtml';
>         $this->render();
>     }
> 
> Which will render the view script in /application/default/views/scripts/
> index.phtml in wich the file _menu.phtml is called with <?php echo $this->
> render($this->actionTemplate); ?> .
> 
> What I'm wondering is where would be a good place to put the site wide view
> scripts such as _menu.phtml (also think header/footer scripts) and what would
> be the best way to use them inside the modules controller ?

initView() uses setScriptPath() to set the view script path. I'd suggest
that in your init() method, you also add one or more additional script
paths -- one for templates common to your entire site:

    function init()
    {
        $this->initView();
        $this->view->config = $this->getInvokeArg('config');
        $this->view->baseUrl = $this->_request->getBaseUrl();
        $this->view->addScriptPath($this->getInvokeArg('siteViewPath'));
    }

Additionally, assuming you have this structure in your modules:

    moduleName/
        views/
            scripts/
                <controller>/
                <controller>/

Then you could also put module-wide templates directly under the
scripts/ subdirectory; these can be called using render and passing
false to the third argument ($noController):

    // render _menu.phtml in moduleName/views/scripts/
    $this->render('_menu', null, false);

Two notes:

    * Passing in false for $noController would also allow specifying
      subdirectories: $this->render('shared/_menu', null, false)
    * If you register additional script paths with the view object, it
      will search through them until it finds (or doesn't find) the
      requested view script. So, the above examples could also look in
      the siteViewPath as registered in the init() example above

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to