codeigniter获取所有声明的路由 [英] codeigniter get all declared routes
问题描述
如何获得codeigniter中的所有声明的路由?像例如。 print_r($ route)
How to get all declared routes in codeigniter? like ex. print_r($route)
因为这是问题,如果客户注册他的用户名为facebook,他将被路由到帐户/ facebook_login,而不是他的个人资料,如果我改变路由的顺序,所有的链接将被路由到客户/配置文件,这是一个没有!
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.
这是我的示例路由:
// 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';
推荐答案
b
$ b
From Controller you can do this
print_r($this->router->routes);
它将显示routes.php中定义的所有路由。
It will show all the routes defined in routes.php.
这篇关于codeigniter获取所有声明的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!