Hmm, yes. After do something like this:

$url = Router::parse($redirect);
$params = $url['params'];
unset($url['params'])
$redirect = Router::url(array_merge($url, $params))

On Thursday, March 19, 2015 at 6:32:07 PM UTC+1, Pgbi wrote:
>
> The reason i need to parse and generate again an url is in the example I 
> gave in my first message:
> In my App, when a user logs in, he is redirected to 
> $this->Auth->redirectUrl() which is of the form 
> /locale/controller/action/param . Before redirecting him, I want to replace 
> "locale" with $user->locale. So I parse the url, replace the locale 
> parameter, and generate the url again.
>
> Does it make sense :) ?
>
>
> Le jeudi 19 mars 2015 02:09:10 UTC-7, José Lorenzo a écrit :
>>
>> Router::url() and Router::parse() are not symmetrical. I don't see the 
>> reason why you want to parse the url and the pass it again to the Router. 
>> Could you explain? 
>>
>>
>> On Thursday, March 19, 2015 at 1:00:16 AM UTC+1, Pgbi wrote:
>>>
>>> Tell me if i'm wrong but i thought that Router::parse was the inverse of 
>>> Router::url.
>>> In other words, I thought that $url == 
>>> Router::url(Router::parse($url))would 
>>> always be true.
>>>
>>> Just found out this was not the case.
>>>
>>> If $url = "/users/view/123" then Router::url(Router::parse($url)) = 
>>> "/users/view?pass%5B0%5D=123"
>>>
>>> This leads to the following bug in my App:
>>>
>>> // In UsersController
>>> function login()
>>> {
>>>     if ($this->request->is('post')) {
>>>         $user = $this->Auth->identify();
>>>         if ($user) {
>>>             $this->Auth->setUser($user);
>>>             $url = $this->Auth->redirectUrl(); // let's say redirect url 
>>> is "/en/users/view/123"
>>>             $url = Router::parse($url); // now url is ['controller' => 
>>> 'users', 'action' => 'view', 'locale' => 'en', 'pass' => ['123']]
>>>             $url['locale'] = $user['locale']; // my user is french
>>>             $url = Router::url($url); // now url is 
>>> "/fr/users/view?pass%5B0%5D=123" 
>>> instead of "/fr/users/view/123"
>>>             return $this->redirect($url);
>>>         }
>>>     }
>>> }
>>>
>>

-- 
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+unsubscr...@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.

Reply via email to