Quantcast

Request Url

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Request Url

Jack Sleight
Hi Everyone,
Just a quick one. My application sits at:
http://locahost/projects/newapp/

Therefore my base URI (from Zend_Controller_Request_Http) is:
/projects/newapp/

And when I request:
http://locahost/projects/newapp/controller/action?test=123

My request URI (from Zend_Controller_Request_Http) is:
/projects/newapp/controller/action?test=123

Question is, is there a method (of Zend_Controller_Request_Http) that'll
return the request URI *without* the base URI? Like this:
controller/action?test=123

If not (which I don't *think* there is), has anyone written one?

Cheers,
--
Jack
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Request Url

Jack Sleight
P.S. I know I could use a simple regex or even regular string replace
to do this, I'm just wondering if there is a better solution that uses
the data already in Zend_Controller_Request_Http?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Request Url

thunder-4
In reply to this post by Jack Sleight
Hi Jack,

How about

$this->getRequest()->getPathInfo() . '?' .
http_build_query($this->getRequest()->getQuery());


Untested, but think will work (or at least, the getPathInfo() and
getQuery() methods provide the data that you're asking for).


Cheers,
Thunder



Jack Sleight wrote:

> Hi Everyone,
> Just a quick one. My application sits at:
> http://locahost/projects/newapp/
>
> Therefore my base URI (from Zend_Controller_Request_Http) is:
> /projects/newapp/
>
> And when I request:
> http://locahost/projects/newapp/controller/action?test=123
>
> My request URI (from Zend_Controller_Request_Http) is:
> /projects/newapp/controller/action?test=123
>
> Question is, is there a method (of Zend_Controller_Request_Http)
> that'll return the request URI *without* the base URI? Like this:
> controller/action?test=123
>
> If not (which I don't *think* there is), has anyone written one?
>
> Cheers,

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Request Url

Jack Sleight
Hi Thunder,
Perfect, thanks! I'd already extended Zend_Controller_Request_Http, so
I just added this method in to my class:

    public function getLocalUri()
    {
                $uri = $this->getPathInfo();
                $query = $this->getQuery();
                if (count($query) > 0) {
                        $uri .= '?' . http_build_query($query);
                }
                return $uri;
    }

Works great. Cheers again,
Jack
Loading...