How to access route, post, get etc. parameters in Zend Framework 2?

Answer

Get a single value:
$this->params()->fromPost('paramname'); // From POST
$this->params()->fromQuery('paramname'); // From GET
$this->params()->fromRoute('paramname'); // From RouteMatch
$this->params()->fromHeader('paramname'); // From header
$this->params()->fromFiles('paramname'); // From file being uploaded

Default values:
All of these methods also support default values that will be returned if no parameter with the given name is found.
example:
$orderBy = $this->params()->fromQuery('orderby', 'name');

Get all parameters:
To get all parameters of one type, just don't pass in anything and the Params plugin will return an array of values with their names as keys
example:
$allGetValues = $this->params()->fromQuery(); // empty method call

Not using Params plugin
example:
$this->getRequest()->getRequest('name', 'default');
$this->getEvent()->getRouteMatch()->getParam('name', 'default');

All zend Framework 2 Questions

Ask your interview questions on zend-framework-2

Write Your comment or Questions if you want the answers on zend-framework-2 from zend-framework-2 Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---