Re: [fw-general] making global view variables visible to view helpers
On Fri, Jan 23, 2009 at 5:51 PM, Matthew Weier O'Phinney matt...@zend.comwrote: -- David Mintz vtbludg...@gmail.com wrote (on Friday, 23 January 2009, 05:06 PM -0500): On Fri, Jan 23, 2009 at 4:36 PM, Matthew Weier O'Phinney matt...@zend.com wrote: -- David Mintz da...@davidmintz.org 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
[fw-general] making global view variables visible to view helpers
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); These view vars are referenced in the layout and/or in the individual views, and it's all good, except in the view helpers. Here, $this-view can see the variables that are set in the view instance by the controller action, but not the ones that are set above in the bootstrap. So -- what am I doing wrong, what's the best practice for setting app-wide view variables? Gratefully, -- David Mintz http://davidmintz.org/ The subtle source is clear and bright The tributary streams flow through the darkness
Re: [fw-general] making global view variables visible to view helpers
-- David Mintz da...@davidmintz.org 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); These view vars are referenced in the layout and/or in the individual views, and it's all good, except in the view helpers. Here, $this-view can see the variables that are set in the view instance by the controller action, but not the ones that are set above in the bootstrap. So -- what am I doing wrong, what's the best practice for setting app-wide view variables? -- Matthew Weier O'Phinney Software Architect | matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] making global view variables visible to view helpers
On Fri, Jan 23, 2009 at 4:36 PM, Matthew Weier O'Phinney matt...@zend.comwrote: -- David Mintz da...@davidmintz.org 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... -- David Mintz http://davidmintz.org/ The subtle source is clear and bright The tributary streams flow through the darkness
Re: [fw-general] making global view variables visible to view helpers
-- David Mintz vtbludg...@gmail.com wrote (on Friday, 23 January 2009, 05:06 PM -0500): On Fri, Jan 23, 2009 at 4:36 PM, Matthew Weier O'Phinney matt...@zend.com wrote: -- David Mintz da...@davidmintz.org 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. -- Matthew Weier O'Phinney Software Architect | matt...@zend.com Zend Framework | http://framework.zend.com/