-- Łukasz Wojciechowski <[EMAIL PROTECTED]> wrote
(on Tuesday, 11 December 2007, 03:11 PM +0100):
> So I managed to run Zend_Layout and I got to the "load of questions" point.
>
> OK, I get the idea of 2 step design but can't get it working ;) I mean
> logically ... I have controller NewsController in witch I have action
> show so I fetch all news in this action and want to show it on layout
> without wondering about navibar (kept in DB) or anything else. How am
> I supposed to retrieve navi bar in my layout. Using
> $this->layout()->render() doesn't actually dispatch my action, right?
> it only renders script.
You should never need to call render() on the layout object from the
layout view helper.
The process is really fairly simple:
* Call Zend_Layout::startMvc() with your configuration options either
in your bootstrap or in a plugin (preferably an early running one)
* Create a layout script that, at the minimum, renders the content
segment of the layout object:
<?= $this->layout()->content ?>
* That's it. Zend_Layout and its various controller plugins and
helpers take care of the rest.
By default, Zend_Layout looks for a script called 'layout.phtml' on your
view script path. If you provide a layoutPath to Zend_Layout, it will
look only in that directory for layout scripts. You can provide a layout
path in a couple ways:
* Pass the layoutPath option to startMvc():
Zend_Layout::startMvc(array('layoutPath' => 'path/to/layouts/'));
* Pass a layoutPath key in a Zend_Config object passed to startMvc():
Zend_Layout::startMvc($config);
* $layout->setLayoutPath();
> I tried to use view plugins ... But it's quite weird place to put navi
> fetch logic in it? ...
View helpers are actually a natural fit for things like navigation. If
you look at all the classic MVC diagrams, they show the view as having
access to the model for read purposes; since navigation is typically a
read-only sort of thing, having a helper for it makes sense.
> I want to get the idea right, I used Smarty and templates so far and
> I'm just used to that approach.
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/