2011-09-27 34 views
2

我只想問,爲什麼一化Zend_Controller_Action操作方法裏面如下:Zend的明確請求參數

$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) 

應該不是「作者」變量太多清除?

在此先感謝!

回答

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; 
} 
+0

非常感謝:) – krzysiek

+0

是有什麼樣一個clearPost方法? setPost不接受空值:/ – krzysiek

+0

您可以使用$ request-> setParamSources(array());這會影響上面的$ paramSources - 如果它設置爲空數組,GET和POST數據不會被檢索。如果其他代碼依賴於getParams,則可能需要將其重新設置爲包括GET和POST。 –

1

要明確PARAMS,你可以簡單地調用:

$request->clearParams();