Skip to content

DrF Reverse Routing

World Wide Web Server edited this page Jul 4, 2012 · 29 revisions

DrF Reverse Routing is an extension of the URL Helper that overrides the site_url function to provide a reverse lookup. If a custom route can be found that matches the given "standard CodeIgniter URI", a custom route URI will be created and returned. Otherwise, a standard site_url will be returned.

[h2]Overview[/h2]

  • Translates a "standard CodeIgniter URI" into a custom route if possible. Standard, in this case, means [em]controller/function/param1/param2/.../paramN[/em]
  • Fails gracefully, providing a standard site_url if no route can be found/translated
  • Works automatically with all of URL Helper's functions
  • Idea inspired by CakePHP's reverse routing

[h2]Download[/h2] File:DrF_Reverse_Routing.zip

[h2]Usage[/h2]

  • place MY_url_helper.php in your system/application/helpers folder
  • include the URL helper in your controller [code]$this->load->helper( 'url' );[/code]
  • use URL Helper's functions as you normally would

[h2]Example[/h2]

  • setup a Test Controller [code] <?php class Test extends MY_Controller{

    function Test() { parent::MY_Controller(); }

    function test( $param1 ){ echo 'You passed in: ' $param1; }

    function redirect() { $this->load->helper( 'url' ); redirect( 'test/test/bar' ); }

} ?> [/code]

Clone this wiki locally