Zend View Action Helper $params questions
i am wondering by what method are the params of a zend view action helper passed by? get
or post
. is is becos i cant seem to access them via $_GET
& $_POST
but i can with $this->getRequest()->getParam("xxx")
then i want to check if the v开发者_运维技巧ariable exists 1st before using it so i did
$itemsPerPage = isset($this->getRequest()->getParam("itemsPerPage")) ? $this->getRequest()->getParam("itemsPerPage") : 5;
which fails with
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
i wonder whats wrong
You can set a default value to be returned if the parameter is not set
$itemsPerPage = $this->getRequest()->getParam('itemsPerPage', 5)
For the cause of your error have a look over there, the same applies for isset()
.
function getFoo()
{
return 'foo';
}
var_dump(isset(getFoo()); // causes Fatal error
$foo = getFoo();
var_dump(isset($foo)); // prints "boolean true"
精彩评论