开发者

Zend clear Request Parameters

开发者 https://www.devze.com 2023-04-07 18:56 出处:网络
I just wanted to ask why the following inside a Zend_Controller_Action action method: $request = $this->getR开发者_开发知识库equest();

I just wanted to ask why the following inside a Zend_Controller_Action action method:

$request = $this->getR开发者_开发知识库equest();
$params = $request->getParams();
var_dump($params);
foreach ($params as $key => &$value) {
    $value = null;
}
var_dump($params);
$request->setParams($params);
var_dump($request->getParams());

produces this:

array
  'controller' => string 'bug' (length=3)
  'action' => string 'edit' (length=4)
  'id' => string '210' (length=3)
  'module' => string 'default' (length=7)
  'author' => string 'test2' (length=5)

array
  'controller' => null
  'action' => null
  'id' => null
  'module' => null
  'author' => null

array
  'author' => string 'test2' (length=5)

Shouldn't the 'author' variable be cleared too?

Thanks in advance!


The getParams method is shown below. What happens is you're clearing the built in params (controller, action etc...) but the method always returns GET and POST variables.

/**
 * Retrieve an array of parameters
 *
 * Retrieves a merged array of parameters, with precedence of userland
 * params (see {@link setParam()}), $_GET, $_POST (i.e., values in the
 * userland params will take precedence over all others).
 *
 * @return array
 */
public function getParams()
{
    $return       = $this->_params;
    $paramSources = $this->getParamSources();
    if (in_array('_GET', $paramSources)
        && isset($_GET)
        && is_array($_GET)
    ) {
        $return += $_GET;
    }
    if (in_array('_POST', $paramSources)
        && isset($_POST)
        && is_array($_POST)
    ) {
        $return += $_POST;
    }
    return $return;
}


To clear params you can simply call:

$request->clearParams(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消