[Solar-talk] helper stack
Paul M Jones
pmjones at solarphp.com
Tue Aug 29 05:35:19 PDT 2006
On Aug 29, 2006, at 5:54 AM, Rodrigo Moraes wrote:
> On 8/28/06, Paul M Jones wrote:
>> The method _setViewLayout() rides to the rescue! ;-) In your app,
>> override it like this:
>>
>> protected function _setViewLayout($view)
>> {
>> // change the view object over to layouts
>> $view = parent::_setViewLayout($view);
>>
>> // now add our own stuff
>> $view->addTemplatePath($this->layout_path);
>>
>> // done!
>> return $view;
>> }
>
> Hm, I think we found a bug! Just overriding it gives a fatal error:
> Call to a member function addTemplatePath() on a non-object... because
> Solar_Controller_Page:: _setViewLayout() currently returns void. It
> misses a "return $view"; add it and the solution will work perfectly.
Oh, sorry, the bugs are in my code above. Because $view is an
object, you don't need to return it; it's passed by reference. The
above code should read:
protected function _setViewLayout($view)
{
// change the view object over to layouts.
// note that $view is an object and is passed
// by reference, and so is modified in-place.
parent::_setViewLayout($view);
// now add our own stuff
$view->addTemplatePath($this->layout_path);
// done! no need to return; $view was passed
// by reference.
}
Sorry to cause confusion.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list