Jay Julian Payne
Jay Julian Payne

Reputation: 780

Zend Framework - Redirects

Running ZF + xampp on localhost (I'm new to this)..

I have this code:

    $url = $this->getRequest()->getRequestUri();
    ...
    $session->requestURL = $url;

& var_dump shows $url=

    /kakool/public/admin/catalog/item/update/1

But later, in this code:

    if (isset($session->requestURL)) {
    $url = $session->requestURL; }
    # again, var_dump shows $url=/kakool/public/admin/catalog/item/update/1
    $this->_redirect($url);  

It's redirecting to this url:

    /kakool/public/kakool/public/admin/catalog/item/update/1

Annoying... Anyone have any ideas?

Upvotes: 0

Views: 67

Answers (2)

Sébastien
Sébastien

Reputation: 48

I think that you have to replace this :

$url = $this->getRequest()->getRequestUri();
...
$session->requestURL = $url;

with this :

$url = $this->getRequest()->getRequestUri();
...
if(!isset($session->requestURL)){
    $session->requestURL = $url;
}

Upvotes: 0

jcsanyi
jcsanyi

Reputation: 8174

The _redirect method defaults to assuming you're giving it a path relative to the root of the current app - so even if you pass a URL starting with /, it'll append the base path to the front of it.

You have two options:

1/ Give it a path relative to the project like it wants:

$url = $this->getRequest()->getPathInfo();
# var_dump now shows $url=/admin/catalog/item/update/1
$this->_redirect($url);

2/ Pass an extra flag that tells the _redirect not to add the base path:

$this->_redirect($url, array('prependBase' => false));

Upvotes: 3

Related Questions