2009年3月17日星期二

Re: [fw-mvc] GET array sent with every request?

J DeBord schrieb:
> Thanks Sven,
>
> I posted to the same yourAction() listed below and isPost returned true
> of course, isGet returned false.
>
> So the only time isGet() is going to return false is when isPost()
> returns true?

If you compare all the is*-methods listed in the manual I linked, only
one of them can return true while all others return false on any single
HTTP request.

> You said "isGet() obviously does not give you the status..." It wasn't
> obvious to me. I thought I'd be able to test to see if a query was
> passed in the URL. Maybe this is due to a lack of experience....
>
> I think the existence of the isGet() method is what confused me. When is
> it logical to use the isGet() method?
>
> Maybe isQuery() would be more appropriate?

You do connect the existance of $_GET, $_POST with the return status of
isGet() and isPost(). There is no such connection besides the names
sounding similar. :)

$_GET is named after the GET HTTP method, because most of the time a
query string is used with this GET HTTP method - and if you use a form
with method="get", all your data ends up in the $_GET array. Same
applies to $_POST: You use a form with method="post", then all your form
data ends up in $_POST. The names are the same, everybody can connect
the method attribute in the form with the variable name, and is happy.

But if you gain a deeper understanding of HTTP itself, you realize that
this simple connection somehow is technically incorrect. $_GET really is
a representation of any query string in the URL, independent of the HTTP
method, so it is not strictly $_GET. The same thing applies to $_POST,
it should really be named something like $_HTTPBODY, because that really
names the part the data is placed - and other methods than HTTP POST
have a HTTP body too, and that data might populate the $_POST array as
well (although I am not sure if current versions of PHP do this already
or should ever do it).

Your question regarding detection of any provided query string data: I'd
would ask getParam() if there is any data (default is to merge $_GET,
$_POST and data passed within a path notation of the URL, such as
http://localhost/controller/action/varname/vardata ). To specifically
ask for $_GET data, use getQuery(), $_POST is available via getPost(),
and any headers usually located in $_SERVER are available via getHeader().

See
http://framework.zend.com/manual/en/zend.controller.request.html#zend.controller.request.http.dataacess
for a little bit more info.

Regards,
Sven

没有评论: