Answer the question
In order to leave comments, you need to log in
Where is the best place to get parameters in a ZF2 application?
Where is it better to take parameters from and how best to pass them:
1) via /route?id=1 and receive as $id=$_GET['id'];, or
2) via $this->params()->fromRoute('id '); ( site.com/controller/view/1 )
What is the conceptual difference? I used to do the 1st option, now I do the 2nd one.
Answer the question
In order to leave comments, you need to log in
$_GET['id']
You can write
instead $this->params()->fromQuery('id')
. Although nothing obliges you to use the Params plugin to get GET parameters .
1. How they look in the URL of the page. Compare:
GET: site.com/test?name=example
ROUTE: site.com/test/example
$this->params()->fromQuery('name');
$this->params()->fromRoute('name');
Something that answers the question "what are we asking for?" - from the route.
And what answers the question "how do we ask?" - from query.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question