Lets say I have the following Request URI: /controller/action/filter//
When I call $this->_getParam(‘filter’) in the controller, it will return NULL. However, I want it to return an empty string.
Am I missing something obvious?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
_getParam() can take a second optional argument holding a default return value. See the note here: http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.accessors
So
$this->_getParam('filter','')should probably do what you need.Edit: thanks for the clarification, gotcha. Not sure sure there’s a particularly clean way to do what you want – looking at the code for
Zend_Controller_Request_AbstractI can see it explicitly deletes the key from the parameter list if it has no value, so there’s no easy way to tell if it was ever there from the controller. Something like the following will do the job, but gets a little ugly (you might be better off using an explicit ‘reset’ value for your filter parameter so you can capture it in a more sane fashion, rather than just an empty string, if that’s possible?).