[Solar-talk] page controller render hooks
Rodrigo Moraes
rodrigo.moraes at gmail.com
Thu Jun 14 15:01:48 PDT 2007
Hi,
I'm adding plugin hooks for an external observer to manipulate views
and layouts. Everything in the page controller is pretty pluggable,
but I think that _renderLayout() needs a small change. Let me explain.
My hooks are added in _render(), _renderView() and _renderLayout() and
do basically the same thing:
protected function _renderView()
{
// notify observer
$observer->notify(...);
if([observer says it is ok to proceed]) {
// Render the view.
parent::_renderView();
}
}
It works well for _render() and _renderView(). The problem is that
_renderLayout() calls _setLayoutTemplates(), which undoes any template
path change that an observer could have done.
My sugestion is to move _setLayoutTemplates() to _render():
if ($this->_layout) {
$this->_setLayoutTemplates()
$this->_renderLayout();
}
So it would still work for existing code, I think, but it would be
more pluggable if I want to extend _renderLayout() to add my own
hooks. I mean, this makes _renderLayout() more reusable or at least
consistent as _renderView() doesn't set template paths; this is done
outside when the view object is built.
Yes, I can add a hook to _setLayoutTemplates() too, but I think we're
complicating things making this necessary. With _setLayoutTemplates()
outside of _renderLayout(), both are still pluggable for those who
want to plug something, with it inside _renderLayout() may have to be
completely overriden. I hope this makes sense.
-------------------------------------------------
End of my most important hook observation.
-------------------------------------------------
Now, something not very important for me, but it came to my mind and I
would like to know what you think: the _postRender() hook became
unnecessary after the recent changes in the page controller, as it is
the last method called. My point is that it is not a good hook as it
can be achieved just by extending _render(), like:
protected function _render()
{
parent::_render();
// run postRender stuff here or call your _postRender() method...
}
It's not a big deal, anyway. I can live perfecly well with it,
although I think it could be perfectly removed as it is a hook that is
already present for any other method - extend it and you have a
"native" hook. :)
That's enough about render hooks! :)
Let me know if I missed something.
-- rodrigo
More information about the solar-talk
mailing list