Developer Blog

  • Blog
  • /
  • Reverse routing
By Dracony on 26 February 2013

If your site has a lot of links, making changes to URL structure can become really frustrating, as you will have to change links in all your views to reflect the new page locations. Now ou can use reverse routing to generate urls based on parameters like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
//Will generate /fairies/view/7
Route::get('default')->url(array(
    'controller'=>'fairies',
    'action'=>'view',
    'id'=>7
));

//You can ommit default and optional parameters
//so this will generate simply /home/list
//(provided controller defaults to 'home'
Route::get('default')->url(array(
    'action'=>'list'
));

You can find more information about routes in the PHPixie Routing tutorial.

comments powered by Disqus