-- David Mintz <[EMAIL PROTECTED]> wrote
(on Thursday, 21 June 2007, 12:45 PM -0400):
> This newbie is liking the Two Step View where your plugin basically intercepts
> the response body and sticks it into a sitewide template at
> dispatchLoopShutdown() time.
>
> So: if you want all your controllers to use a common Zend_View object (so that
> the view vars they set will end up available to the sitewide, enclosing
> template), what approach would you recommend? In the name of DRY it seems you
> would might have your bootstrap put the new Zend_View() in the registry, and
>
> class MyAppController extends Zend_Controller_Action
>
> {
> public function init() {
>
> $this->view = Zend_Registry::get('view');
> }
> }
>
> and then have your controllers extend MyAppController instead of
> Zend_Controller_Action. Thoughts?
There's another way to do this now with the ViewRenderer:
class My_TwoStep_Plugin extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$viewRenderer =
Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer');
$view = $viewRenderer->view;
// ... do the rest...
}
}
No registry needed. :-)
You can also seed the ViewRenderer with a customized view object in your
bootstrap:
$view = new Zend_View($options);
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/