[Solar-talk] Layouts and modifying the view stack
Rodrigo Moraes
rodrigo.moraes at gmail.com
Fri Nov 17 12:25:40 PST 2006
On 11/17/06, Andreas Ravnestad wrote:
> However though, it only works if I call
> $this->template() on the common templates from a view. If I call
> $this->template() on the common templates from a *layout*, Solar gives
> an error (see attached error message at the end of this mail).
>
> How can I make this work from layouts?
Hi,
This is indeed confusing; in short words there are *two* stacks: one
for the layout and another for the view. To avoid confusion, I add the
/View directory to the *layout* path stack:
protected function _setViewLayout($view)
{
// change the view object over to layouts.
parent::_setViewLayout($view);
// get the current class
$class = get_class($this);
// now add our own stuff
$template = array();
$template[] = str_replace('_', DIRECTORY_SEPARATOR, "{$class}_View");
$view->addTemplatePath($template);
}
Then you can include templates stored in /View in a layout or a view. :-)
Have fun.
rodrigo
---------------------------------------------------------------------
Solar has now a Community Wiki: solarphp.org
---------------------------------------------------------------------
Join the #solarphp IRC channel on freenode.org
---------------------------------------------------------------------
More information about the solar-talk
mailing list