on getQuery()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

on getQuery()

dennis-fedco
What is the rationale behind using $request->getQuery() vs using $_GET directly?

is getQuery() there to provide an Object Oriented way of accessing $_GET, or is there more to it?

Because from initial testing ... I do not see much different except the syntax.
And the ability to use default value, i.e getQuery('var', 'default');
Reply | Threaded
Open this post in threaded view
|

RE: on getQuery()

demiankatz
It is often useful to wrap commonly-used features like this -- for example, so you can easily test code using mock objects. The defaulting feature is a useful bonus, too, as you observe. This all goes with the framework's overall dependency-injection philosophy -- rather than accessing $_GET (which is a global variable, which allows the code to magically pull values out of the air), wrapping $_GET in the request object provides a more clearly-defined (and easily overrideable) origin for the data.

- Demian

> -----Original Message-----
> From: dennis-fedco [mailto:[hidden email]]
> Sent: Thursday, June 12, 2014 10:07 AM
> To: [hidden email]
> Subject: [fw-general] on getQuery()
>
> What is the rationale behind using $request->getQuery() vs using $_GET
> directly?
>
> is getQuery() there to provide an Object Oriented way of accessing $_GET, or
> is there more to it?
>
> Because from initial testing ... I do not see much different except the
> syntax.
> And the ability to use default value, i.e getQuery('var', 'default');
>
>
>
> --
> View this message in context: http://zend-framework-
> community.634137.n4.nabble.com/on-getQuery-tp4662135.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]