(on Tuesday, 17 March 2009, 11:07 AM +0100):
> 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?
No. isGet() and isPost() look at $_SERVER['REQUEST_METHOD'], which tells
what HTTP request method was used. isGet() returns true if
$_SERVER['REQUEST_METHOD'] is 'GET'; isPost(), 'POST'. There are other
HTTP request methods as well, though not all servers support them: HEAD,
PUT, and DELETE. We have methods for each of these as well.
> 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?
It sounds like what you're trying to do is to see if there are any
variables passed in the query string. To do this, pull the value of
getQuery() and check to see if it's empty:
$query = $request->getQuery();
if (empty($query)) {
// no parameters passed in query string
}
> On Tue, Mar 17, 2009 at 10:09 AM, Sven Rautenberg <sven.rautenberg@mayflower.de
> > wrote:
>
> J DeBord schrieb:
> > Thanks Sven,
> >
> > Looking at the action below, and accessing it from
> > http://localhost/controller/your
> >
> > public function yourAction() {
> >
> > $request = $this->getRequest();
> >
> > echo ($request->isPost() ? 'Is Post' : 'Is Not Post') . '<br />';
> > echo ($request->isGet() ? 'Is Get' : 'Is Not Get') . '<br />';
> >
> >
> > }
> >
> > Output:
> >
> > Is Not Post
> > Is Get
> >
> > I would expect it to echo "Is Not Get."
>
> But that's not what you have there. You can either have a GET request,
> or a POST request (besides any of the other requests that HTTP defines).
>
> isGet() obviously does not give you the status whether or not the
> request contained any query string or additional components within the
> URL, but tells you what kind of HTTP request was received. And that has
> to be GET at least.
>
> See
> http://framework.zend.com/manual/en/zend.controller.request.html#
> zend.controller.request.http.method
>
> I think your misconception of what $_GET really is comes from the name
> $_GET. This variable really should be named $_QUERY, because it does not
> only exists with GET requests, but can exists with POST requests as
> well. Just try <form action="target.php?test=get" method="post"> and
> have a look at $_GET. :)
>
> Regards,
> Sven
>
>
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论