I am new to PHP frames and am building a REST API on Zend Framework 2. I want to add params to Request. I could not find a method for adding parameters, so I will do this by getting all the parameters, adding new parameters for them, and then setting this new set of parameters Request. I get parameters using
$this->params()->fromQuery()
but I cannot find a way to return params to Request. Is there any method for this?
EDIT: I tried below. Which does not give the desired result.
In Module.php:
public function onBootstrap(\Zend\Mvc\MvcEvent $e)
{
$em = $e->getApplication()->getEventManager();
echo "Outside";
$em->attach (MvcEvent::EVENT_DISPATCH, function(MvcEvent $e) {
echo "Inside";
$routeMatch = $e->getRouteMatch();
$routeMatch->setParam("myParam", "paramValue");
});
}
In my controller
echo "myParam : " . $this->params()->fromQuery('myParam');
null, . - , ( ), Dispatch ( RouteMatch).
Outside
myParam :
Inside