2010-07-22 44 views
0

我想知道什麼方法是一個zend視圖動作助手傳遞的params? getpost。是是becos我似乎無法通過$_GET & $_POST訪問他們,但我可以$this->getRequest()->getParam("xxx")

然後我要檢查,如果變量使用它,所以我做了

$itemsPerPage = isset($this->getRequest()->getParam("itemsPerPage")) ? $this->getRequest()->getParam("itemsPerPage") : 5; 

其失敗

之前存在1

Fatal error: Can't use method return value in write context in D:\Projects\Websites\php\ZendFramework\LearningZF\application\controllers\IndexController.php on line 21

我不知道什麼是錯

回答

4

您可以設置一個默認值返回如果該參數沒有設置

$itemsPerPage = $this->getRequest()->getParam('itemsPerPage', 5) 

爲了您的錯誤的原因有過目there,同樣適用於isset()

function getFoo() 
{ 
    return 'foo'; 
} 

var_dump(isset(getFoo()); // causes Fatal error 

$foo = getFoo(); 
var_dump(isset($foo)); // prints "boolean true" 
+0

哦所以'isset'只會檢查變量不能從函數返回值嗎? – 2010-07-22 13:31:23

+0

準確地說:「isset()只適用於變量,因爲傳遞任何東西都會導致分析錯誤。」 – 2010-07-22 14:03:16