Reputation: 1246
There are multiple ways to get parameters from a route in zf2. A couple include
$pageID = (int)$this->getEvent()->getRouteMatch()->getParam('pageID');
and
$pageID = (int) $this->params()->fromRoute('pageID', 0);
Which is the best, and why?
Upvotes: 0
Views: 48
Reputation: 51
$pageID = (int) $this->params()->fromRoute('pageID', 0);
This is the controller action helper call and should be used inside your controller. Inside the helper
$this->getEvent()->getRouteMatch()->getParam()
is called.
As u can see - both ways are legit - the helper call is, as the name says, a tool to spare you some typing.
You can use the first way to get parameters inside an attached event for example, most of the time used when u attach something to the default ZF2 events like dispatch, render ...
greetings
Upvotes: 1