Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.9.3
-
Component/s: Zend_Controller
-
Labels:None
Description
Hi,
I'm building a CMS system upon the Zend Framework. But I'm having troubles with the Request object, which seems not to "clear" the user params. Each page exists of several page elements; each element is a new request that is added to the actionstack. If the request's user params are printed in the IndexController everything is fine, but when I print the same request in the controller for that specific action than I see also user params of the previous actions.
// this code is in the IndexController in the "default" module foreach($elements as $arr) { // clone request object for each action $req = clone $request; // set controller, action and module name $req->setActionName($arr["action"]); $req->setControllerName($arr["controller"]); $req->setModuleName($arr["path"]); $req->setParam("_pageElementID", $arr["elementID"]); // add custom parameters if($arr["params"]) { $params = explode("/", $arr["params"]); foreach($params as $param) { list($key, $val) = explode("=", $param); $req->setParam("_".$key, $val); } } $this->_helper->actionStack($req); // add element request to action stack }
Printout of two request params:
Array
(
[_moduleContentKey] => leftmenu
[_pageElementID] => 14
[_startLevel] => 1
[_test] => 1
)
Array
(
[_moduleContentKey] => default
[_pageElementID] => 3
[_startLevel] => 1 // parameter is a "leftover" from the previous action
[_test] => 1 // parameter is a "leftover" from the previous action
[_showRoot] => 1
)
Possible solution:
Add a clearParams method to Zend_Controller_Request_Http:
public function clearParams() { $this->_params = array() }
Then this method should be called from the ActionStack plugin when the _forward method is triggered for the next action.
Is this the right way to handle this problem? Honestly I don't like to change the code from the Zend Framework...
Thx in advance for your comments and advice,
Cheers,
Stijn
This is a more serious bug than perhaps it has appeared, as it prohibits the use of ActionStack in many cases. It's a trivial fix (it seems) and would be good to solve.
Another (possibly simpler) solution would be to replace the ActionStack::forward($next) method with
public function forward(Zend_Controller_Request_Abstract $next)
{
$this->setRequest($next);
}