Mathew,

That's exactly the kind of elegant solution I was looking for.
Thanks for your fast reply.

I still have a little problem though.
Unless I misundersood something, when I put

   // rendering /application/default/views/scripts/_menu.phtml
   $this->render('_menu', null, true);

in /application/default/views/scripts/index/index.phtml

I get a fatal error:

*Fatal error*: Uncaught exception 'Zend_View_Exception' with message 'script
'_menu' not found in path' in
C:\Eclipse\e-workspaces\mcarpentier\SIMON\library\Zend\View\Abstract.php:595
Stack trace: #0

(After looking the documentation, I found out $noController need to be set
to true in order to get the behavior you described)

Can you see what's wrong in what I try to do ?


Also, on a side note regarding my other inquiry, where would be good place
to put the siteView scripts (as "best practice") ?

I can see some options:

1) placing them in the default module views/scripts folder. This feels a bit
awkward since the script are not specific to the module

2) placing them in /application/views. Seems like a good idea to me but I
find annoying to mix module folders with other folder like config, views,
etc.

What would you suggest ?


On 3/29/07, Matthew Weier O'Phinney <[EMAIL PROTECTED]> wrote:

-- 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.1from
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/




--
Martin Carpentier

Reply via email to