Maybe because they’re so undocumented and ambiguous, but there’s something about Cake URL routes that have both fascinated and frustrated me. In my one+ year history with Cake, I have gone about several methods of planning and executing routing, striving to provide a clean, relevant (& seo friendly) url structure without being counterproductive to the conventions of Cake.
Recently I had a rather unique challenge come across my plate. It was a potentially complex routing situation where the parameter needed to be between the controller and the view in the url structure. Visually, ‘/controller/parameter/view’. It made total sense seo wise, and if I could make it work right, wouldn’t affect Cake conventions at all. However, I wasn’t even sure if this method was possible.
The solution, as it turns out, was amazingly simple.
In the Routes declaration, simply set the wildcard (*) in the middle of the model name and the view name. Visually,
$Route->connect('/controller/*/view', array('controller' => 'controller', 'action' => 'view'));
There! And now you can recursively route.
0 Responses to “Recursive Routes with Cake 1.1”
Leave a Reply