On Fri, Jan 23, 2009 at 5:51 PM, Matthew Weier O'Phinney
<[email protected]>wrote:

> -- David Mintz <[email protected]> wrote
> (on Friday, 23 January 2009, 05:06 PM -0500):
> >
> >
> > On Fri, Jan 23, 2009 at 4:36 PM, Matthew Weier O'Phinney <
> [email protected]>
> > wrote:
> >
> >     -- David Mintz <[email protected]> wrote
> >     (on Friday, 23 January 2009, 04:14 PM -0500):
> >     > I have view variables that I want to be set in every view instance
> --
> >     things
> >     > like paths to public resources. So I have been doing something
> stolen
> >     from an
> >     > example somewhere a long while ago:
> >     >
> >     > $view = new Zend_View;
> >     > $view->web_root =
> Zend_Registry::get('siteConfig')->paths->web_root;
> >     > if (Zend_Auth::getInstance()->hasIdentity()) {
> >     >     $view->user = Zend_Auth::getInstance()->getIdentity();
> >     > }
> >     > // etc
> >     > $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
> >     > $viewRenderer->setView($view);
> >     > Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
> >
> >     Try changing the above three lines to this, and see if it makes any
> >     difference:
> >
> >        $viewRenderer =
> Zend_Controller_Action_HelperBroker::getStaticHelper
> >     ('viewRenderer')
> >        $viewRenderer->setView($view);
> >
> >
> >
> > Same story. e.g., I stick this stdClass $user object in the view in my
> > bootstrap, and can dump it in the view, but the helper doesn't see it.
> How do
> > people deal with this? It's got to be a common scenario. I suppose I
> could pass
> > whatever to the helper as args to the helper call.
> >
> > Would it make a difference if I set these view vars in a plugin? Hmm I
> think
> > I'll try and see for myself...
>
> Shouldn't make a difference. The other possibility is that it's an issue
> in your helper. Are you extending Zend_View_Helper_Abstract? That class
> provides a setView() implementation, which will ensure that $this->view
> is available in your helper.
>

This is the whole thing, except I deleted the body of the one function for
brevity.

$this->view is in fact set and available to the helper, but, as I say,
$this->view does not see the vars I set in the bootstrap. Makes me think
it's either not a ref to the same object, or else this stuff with
$this->view is executing before the assignment stuff in the bootstrap -- not
likely.

class  Zend_View_Helper_RequestStatus extends Zend_View_Helper_Abstract {

    public function RequestStatus($event_id) {
        // echo empty($this->view->user) ? " ... no user ... " : " ... yes
user ...";
       // do things, and return an informative string instead of a digit
            }

        }
    }
}


-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness

Reply via email to