ZF-3036: View Filters can have an incorrect View assigned to them
Description
I found what appears to be a bug in the code that performs filtering for views. In the View->getFilter method there is a check for a setView method on the retrieved Filter object. If this method is found the current view will be assigned to the Filter. Since Filters are "cached" in the _filterXXX variables of the View class they can be persistent through multiple runs of the View if a global View has been assigned to the ViewRenderer helper. This is especially true for Layout based sites. This leads to two issues: (a) one View that has Controller Action specified values assigned to it could have those values be available by another View script and (b) Controller assigned View script values not being made available to already instantiated Filters.
The simple fix to this issue is to have the check for the "setView" method pulled out of the current IF block and made in parallel to the primary IF.
Here is the current code (as of 1.5.0):
(Zend_View_Abstract.php)
public function getFilter($name)
{
if (!isset($this->_filterClass[$name])) {
$class = $this->_loadClass('filter', $name);
$this->_filterClass[$name] = new $class();
if (method_exists($this->_filterClass[$name], 'setView')) {
$this->_filterClass[$name]->setView($this);
}
}
return $this->_filterClass[$name];
}
Here is my new proposed code:
public function getFilter($name)
{
if (!isset($this->_filterClass[$name])) {
$class = $this->_loadClass('filter', $name);
$this->_filterClass[$name] = new $class();
}
if (method_exists($this->_filterClass[$name], 'setView')) {
$this->_filterClass[$name]->setView($this);
}
return $this->_filterClass[$name];
}
Comments
Posted by Wil Sinclair (wil) on 2008-04-18T16:01:32.000+0000
Please evaluate and categorize/assign as necessary.
Posted by Ralph Schindler (ralph) on 2008-04-22T10:40:25.000+0000
Updating project management info.
Posted by Jon Whitcraft (sidhighwind) on 2008-10-23T18:48:38.000+0000
Have you tested this since 1.6 got released where it's using hte plugin manager now instead of the _loadClass Method? If not can you please provide a unitTest for this so we can work on the problem.
Posted by Jon Whitcraft (sidhighwind) on 2009-02-06T09:34:21.000+0000
Making the code readable.
Posted by Jon Whitcraft (sidhighwind) on 2009-10-15T10:53:16.000+0000
Closed as Not an Issue as there has been no activity for a while. Please reopen if this is still an issue.