codeigniter get all declared routes

自闭症网瘾萝莉.ら 提交于 2019-12-04 04:34:29

From Controller you can do this

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

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

born2code

First of all I'm sorry for my English because "I am NOT SCHOOL". I didn't get much what you are trying to point out. Maybe you want to do similar with this http://www.hirepinoy.com/born2code. But in my experience with CodeIgniter,it is a bad idea to declare $route['(:any)'] = 'customer/profile/$1'; in your routes.

I think the best option you can do is that to create a class to check if username exist in the table of users by using HOOK see http://codeigniter.com/user_guide/general/hooks.html. So therefore when username (unique field) returned then you can modify the $_SERVER['REQUEST_URI'] to be like this

$_SERVER['REQUEST_URI'] = '/customer/profile/'.$username;

So basically it will modify the SERVER REQUEST before the codeigniter core process it's core processing.

Now, the problem maybe, is when user registered a username that is the same with your controller for sure will not be process since it was modified to route on costumer/profile/blahblah. All you need to do is to create a custom validation to check weather the username already exists on database and or your controller name.

You can do like

if (file_exists(APPPATH."controllers/{$value}.php")) {
    $this->CI->form_validation->set_message('is_unique', 'Username is already taken');  
    return FALSE;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!