Issue Type: Bug Created: 2011-05-24T13:59:48.000+0000 Last Updated: 2011-08-07T12:28:57.000+0000 Status: Open Fix version(s): Reporter: Aleksey 'Xerkus' Khudyakov (xerkus) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View
Related issues: Attachments: - ZF-11405.patch
Currently view inject itself into helpers only on helper instantiation. It is expected that helper contains current view object when called. It is true unless view object already instantiated helper and was cloned. In this case cloned view contains same helper instance as original view. And that helper contains original view if called from cloned view.
<pre class="highlight"> $this->setScriptPath('/some/path/to/view/scripts'); $this->partial('partial_in_path_specified_above.phtml'); //oops, wrong view here, as partial uses original view and we in cloned one
Example above involves partial helper, but this is most important with custom helpers. I can provide several use cases i had in mind if needed.
As workaround in my helpers with view dependency first parameter of direct() method is required instance if zend_view, so any call to this helpers looks like $this->fooHelper($this, ...); This ensures noone can forget to set view.
After some digging I think best way to fix this is to make sure view instance is current or inject it every time helper is called. As someone suggested, cloning helpers is a bad idea. We can't just set view on clone.
Ps: Actually I think internal array of helpers should be replaced with some sort of container or instance of helper broker so views can share helpers unless they told not to. It will introduce BC break though so it is completely out of scope here.
Posted by Aleksey 'Xerkus' Khudyakov (xerkus) on 2011-05-24T15:52:33.000+0000
attached patch with tests
Have you found an issue?
See the Overview section for more details.