-- Martin Carpentier <[EMAIL PROTECTED]> wrote
(on Thursday, 29 March 2007, 05:09 PM +0200):
> 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
It appears that render() didn't append the script suffix (by default,
.phtml). Did you override the render() method, by any chance?
Also, can you verify that _menu.phtml exists somewhere in the view
script path you specified? (just want to rule out all possibilities).
> (After looking the documentation, I found out $noController need to be set to
> true in order to get the behavior you described)
Oops! My bad! Yes, it needs to be set to true -- i.e., $noController ==
true.
> 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
My site architecture usually looks like this:
application/
controllers/
models/
views/
scripts/
helpers/
filters/
modules/
...
and I set the 'default' module to point to application/controllers. To
my mind, the 'default' module is for general purpose site functionality
-- user login, static content, etc. -- so having sitewide scripts in
that folder makes sense to me. More below, though...
> 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.
However, I have also done this, and think it's perfectly appropriate.
The top level application directory implies that these are items that
will be used site-wide -- configuration files, general purpose view
scripts (and sitewide templates) and helpers, etc. One layout I did this
way looked like:
application/
config/
data/
lib/
modules/
default/
controllers/
models/
views/
.../
views/
which presented a very nice layout.
I know Gavin is working on a tutorial that addresses some of these
issues -- don't have the URLs off-hand, but he posted them in the past
day or two to either the fw-mvc or fw-general list.
> 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.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/