Thursday, November 13, 2014

Re: Parsed url / Redirect - base issue

It's been a while now but I had the same question and I found the anwser:

There are a few 'special' parameters that can change the final URL string that is generated:

  • base - Set to false to remove the base path from the generated URL. If your application is not in the root directory, this can be used to generate URLs that are 'cake relative'. CakePHP relative URLs are required when using requestAction.
$url = Router::url(array('controller' => 'user', 'action' => 'view', 5, 'base' => false));

http://book.cakephp.org/2.0/en/development/routing.html#custom-route-classes




On Tuesday, November 13, 2012 12:21:36 PM UTC-2, Vanja Dizdarević wrote:
I have an 2.1.1 app under a sub-path (example.com/app-name/).

I am doing a redirect like this:

$url = Router::url(array('controller' => 'user', 'action' => 'view', 5)); //yields "/app-name/user/view/5"
$this->redirect($url);

Redirects to '/app-name/app-name/user/view/5'. Essentially double-basing the url.

How can I:

A: Redirect to the direct url without using server name?
B: Get the app-relative path (/user/view/5)

Keep in mind that $url value is passed around and cannot be passed to the $this->redirect as an array.

I have also tried Router::parse('/app-name/user/view/5'); which gives me controller=> 'app-name', etc...

Thanks!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: