-- Philip G <[EMAIL PROTECTED]> wrote
(on Wednesday, 06 February 2008, 02:06 PM -0600):
> On Feb 6, 2008 1:42 PM, Matthew Weier O'Phinney <[EMAIL PROTECTED]> wrote:
> > -- Philip G <[EMAIL PROTECTED]> wrote
> > (on Wednesday, 06 February 2008, 01:19 PM -0600):
> > > Forgive the back-to-back emails.
> > >
> > > I have a question about Zend_Layout's setup, well, a couple.
> > >
> > > First off, isn't it a bit odd to "start" the MVC from Zend_Layout? I
> > > would think you would "startMVC" from your base loader file
> > > (index.php) against the Zend_Controller_Front. I don't know. I just
> > > think it feels odd to "startMVC" from the Layout class when by the
> > > time the Layout is used, the MVC would have been started (controller
> > > calls the layout).
> >
> > Well, technically it's not starting the MVC... it's starting
> > *integration* with the MVC layer. But I, for one, felt that
> > Zend_Layout::startMvcIntegration() was getting to be a bit much to type.
> >
> 
> Okay, I can see it's starting the integration. I still don't see why
> integration should be started at the View level (eg Layout level) and
> not the Controller level.

It's to simplify the setup, and it's for seeral reasons. First, to
ensure that all the various integration points are using the same
object, and to allow custom code (including the Layout view helper)
access to that same object without needing to do crazy code acrobatics,
we initialize a static member in Zend_Layout. Second, there are several
places where Zend_Layout needs to register -- a plugin and an action
helper. I for one don't want to write the following code every time I
want to use layouts:

    $layout = new Zend_Layout($config);
    $front->registerPlugin(new Zend_Layout_Controller_Plugin_Layout($layout));
    Zend_Controller_Action_HelperBroker::addHelper(
          new Zend_Layout_Controller_Action_Helper_Layout($layout)
    );
    $view->getHelper('layout')->setLayout($layout);

Sure, startMvc() could have potentially been incorporated into
Zend_Controller_Front, but nobody suggested that when Zend_Layout
development was occurring; the predominant opinion was to keep the
integration contained in Zend_Layout.

> > startMvc() does a few things:
> >
> >   * Instantiates the layout object and registers it in a static instance
> >   * Instantiates and registers the Layout plugin, to automate rendering
> >     the layout script.
> >   * Instantiates and registers the Layout action helper, to give layout
> >     awareness to your action controllers
> >
> 
> That's sounds like startLayout() since startMvc() implies starting the
> controller and models.
> 
> I can see startMvc() fitting in perfectly well at the start, when you
> dispatch(). Instead of calling dispatch() you called startMvc() and
> the magic happens.
> 
> The also would allow you to separate the Zend_Controller from the
> Zend_View (the initial directly ZFW went). startMvc() will integrate
> everything where dispatch() will only dispatch the controllers.
> 
> Maybe it's just too late to do such a big change, now. But that's how
> I imagine it playing out.

While I can understand what you're saying, I feel this is coming too
late; Zend_Layout, while it hasn't been officially released, *has* been
in core since mid-November, and there have been tutorials and code
written against them. 

> > > Second one being, how do I get Zend_Layout to auto-recognize a
> > > "layout" directory? The problem I'm running into is when I specific
> > > ->setLayoutPath('./layouts'); it doesn't properly prepend my full file
> > > system path in front of that.
> >
> > Use
> >
> >     dirname(__FILE__) . '/layouts'
> >
> > instead of './layouts'; if you want to be real paranoid, use
> > realpath(dirname(__FILE__)).
> >
> > This is not a bug of Zend_Layout, but rather a more general PHP issue
> > regarding include_paths.
> 
> Unfortunately that doesn't work very well either. The app directory is
> custom and can be anywhere on the file system. And I'm instantiating
> Zend_Layout from within my Controller_Plugin class which is located
> within its own directory structure (so overlapping dirname() calls
> won't work).

Sounds to me like you need to inform your controller plugin of the
current location of the bootstrap and application directories -- perhaps
via a config setting or hinting via Zend_Controller_Front params?

> Zend_View automatically adds the full path properly. 

I'd bet that if you say $view->addScriptPath('./layouts'), it *won't
work correctly. More on that below.

> Why can't Zend_Layout do so as well? It seems rather odd. It can be
> something as simple as if layout path doesn't start with '/', prepend
> the view or model directory path.

Except that Zend_View and Zend_Layout are unaware of Zend_Controller and
its family -- they have no concept of the class calling them.

The seeming awareness that Zend_View has is due to injection from the
ViewRenderer, which *does* have knowledge of the current module,
controller, and action, and injects a path to the current controller's
view scripts into the view object based on that information.

Zend_Layout is *supposed* to be unaware of the individual controllers
because it is supposed to wrap whatever content has already been
rendered by whatever controllers and actions that have done so.

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

Reply via email to