In beta5 zf2, it has changed to be easier to use, so you donβt need to remember different syntaxes for each other type. i cite :
New Params controller plugin. Allows you to receive a request, message, cookie, header and route parameters. Using $ this-> params () -> fromQuery ($ name, $ default).
So, to get the parameter from the route, all you have to do is.
$param = $this->params()->fromRoute('pageId');
This can also be done with the request ($ _GET) and post ($ _POST), etc., as the quote says.
$param = $this->params()->fromQuery('pageId'); // will match someurl?pageId=33 $param = $this->params()->fromPost('pageId'); // will match something with the name pageId from a form. // You can also set a default value, if it empty. $param = $this->params()->fromRoute('key', 'defaultvalue');
Example:
$param = $this->params()->fromQuery('pageId', 55);
if url is someurl? pageId = 33 $ param will contain the value 33. if the URL does not have? pageId $ param will contain a value of 55
source share