R
R
roman_lyce2015-05-27 16:17:53
Zend Framework
roman_lyce, 2015-05-27 16:17:53

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

2 answer(s)
C
Cat Anton, 2015-05-27
@roman_lyce

$_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

2. You can put arrays in GET:
Nothing prevents you from using both options at once:
$this->params()->fromQuery('name');
$this->params()->fromRoute('name');

O
OnYourLips, 2015-05-27
@OnYourLips

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 question

Ask a Question

731 491 924 answers to any question