views:

30

answers:

1

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 variable 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

+1  A: 

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"
Benjamin Cremer
oh so `isset` will only check variables not return value from functions?
jiewmeng
Exactly: "isset() only works with variables as passing anything else will result in a parse error."
Benjamin Cremer