Search code examples
phpcodeigniterroutes

codeigniter get all declared routes


How to get all declared routes in codeigniter? like ex. print_r($route)

Because this is the problem, if the customer registered his username as 'facebook' he will be routed to account/facebook_login and not to his profile, if i changed the order of routes, all links will be routed to customer/profile and this is a no no!

So basically, instead of listing all the routes that i declare and put it into an another array or db table, i want to loop into route array and check if there is a word that has been declared already so that i can stop them to register that word as their username.

this is my sample routes:

// Account routes
$route['login'] = 'account/login';
$route['logout'] = 'account/logout';
$route['register'] = 'account/register';
$route['facebook'] = 'account/facebook_login';
$route['twitter'] = 'account/twitter_login';
$route['settings'] = 'account/settings';

$route['validate/(:any)'] = 'validate/$1';

// Dynamic routes
$route['(:any)'] = 'customer/profile/$1';

Solution

  • From Controller you can do this

    print_r($this->router->routes);
    

    It will show all the routes defined in routes.php.