Zend清除请求参数

时间:2011-09-27 15:07:17

标签: php zend-framework parameters front-controller

我只想问一下Zend_Controller_Action操作方法中的以下原因:

$request = $this->getRequest();
$params = $request->getParams();
var_dump($params);
foreach ($params as $key => &$value) {
    $value = null;
}
var_dump($params);
$request->setParams($params);
var_dump($request->getParams());

产生这个:

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)

不应该清除'author'变量吗?

提前致谢!

2 个答案:

答案 0 :(得分:1)

getParams方法如下所示。你正在清除内置参数(控制器,动作等......),但该方法总是返回GET和POST变量。

/**
 * 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;
}

答案 1 :(得分:1)

要清除params,您只需致电:

$request->clearParams();