Reputation: 8111
I am using ZF2 modules, but I am not using full ZF2 framework stack.
I need to be able to pull GET
parameters from URL string into my Controller.
I've created a Controller
that extends AbstractActionController
of ZF2. After reading ZF2: Get url parameters in controller, I have used print $this->params('line');
to try to print $_GET['line']
value, but nothing shows up.
In short, this is supposed to work, but doesn't:
//ZF2 equivalents of print $_GET['line'] (either one should work)
print $this->params('line');
print $this->getEvent()->getRouteMatch()->getParam('line');
I imagine it is due to lack of mechanism to populate params
from $_GET
. How can I get that part of ZF2 mechanism into my code?
And is it worth the trouble? For example, if I need to introduce routes, events, and pretty much bring the entire ZF2 framework into my code, and significantly rewire my app for this to work, I might want to just stick to $_GET
method, at least for now.
Upvotes: 1
Views: 174
Reputation: 1176
I'm not sure if this is much of an answer, but it might be at least helpful. So, disclaimer: I didn't try this.
So you extended the AbstractActionController
, which is nice because it's full of features. The AbstractActionController
implements a whole list of interfaces that makes the controller listen to MvcEvents, uses the Service Locator, etc. If you are not supplying the controller with a ServiceLocator etc., then there is no point in extending the AbstractActionController
. Use the DispatchableInterface
instead! Also, read up on: http://framework.zend.com/manual/current/en/modules/zend.mvc.controllers.html
Now, if you do want to use the features of the AbstractActionController
you will need the \Zend\Mvc package. Which comes with all of the features or overhead - which of these is the case depends on your application. Note that the Zend MVC application is actually very performant, but if you are not planning on reusing those components you might be actually better off without them. The manual actually indicates how to bootstrap Zend MVC: http://framework.zend.com/manual/current/en/modules/zend.mvc.intro.html#bootstrapping-an-application. If you succeed in bootstrapping, you should be fine, and be able to use your controllers.
Upvotes: 2
Reputation: 32
You might try
print $this->params()->fromQuery('line');
According to this http://zf2cheatsheet.com/
Upvotes: 0