#6369: Router::parse result array used in url, redirect
-----------------------------------+----------------------------------------
Reporter: ecamaj | Type: Enhancement
Status: new | Priority: Medium
Milestone: 1.2.x.x | Component: Routing/Dispatcher
Version: 1.2 Final | Severity: Normal
Keywords: Router parse array | Php_version: n/a
Cake_version: 1.2.3.8166 |
-----------------------------------+----------------------------------------
I thought it is almost impossible that method that will give me string url
from Router::parse result array does not exists, but after consulting with
some old CakePHP gurus on IRC channel it seems to be so.[[BR]]
[[BR]]
'''A problem'''[[BR]]
[[BR]]
I needed to parse page url string which i got from
$this->Auth->redirect(). Auth->redirect gives back a plain string
url.[[BR]]
[[BR]]
'''A idea'''[[BR]]
[[BR]]
Using Router::parse that will understand all applied routes to that url
string and will give me back an array which i can easily manipulate.[[BR]]
After that i needed that array back to url string or some kind of array
that i can use in $this->redirect (that Router::url understands).[[BR]]
[[BR]]
'''Why it doesn't work'''[[BR]]
[[BR]]
Router::url will not accept an array that contains arrays in it and that
is exactly what Router::parse will give you. It will contain "url", "pass"
and "named" arrays in it.[[BR]]
[[BR]]
Example:[[BR]]
{{{
Array
(
[pass] => Array
(
[0] => user1
)
[named] => Array
(
[named_key] => named_value
)
[plugin] =>
[controller] => users
[action] => add
[url] => Array
(
[ext] => html
)
)
}}}
If this array is tried to be used in Router::normalize, Router::url or
redirect it will give:[[BR]]
[[BR]]
''Array to string conversion [CORE/cake/libs/router.php, line 956]''[[BR]]
(mapRouteElements method)[[BR]]
[[BR]]
'''Possible solution'''[[BR]]
[[BR]]
Unsetting "url" array and merging all other subarrays into main array so
that we get an array like:
{{{
Array
(
[0] => user1
[named_key] => named_value
[plugin] =>
[controller] => users
[action] => add
)
}}}
and then this array can be used in all Router methods as valid
array.[[BR]]
[[BR]]
'''Conclusion'''[[BR]]
[[BR]]
I hope that this will be added because i heard of several people that they
had to hack Router::parse array in various way to do exactly the same
thing as i needed.[[BR]]
[[BR]]
Gurus included. ;-)
--
Ticket URL: <https://trac.cakephp.org/ticket/6369>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---