codeigniter get all declared routes

前端 未结 2 1611
死守一世寂寞
死守一世寂寞 2021-01-02 12:32

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

相关标签:
2条回答
  • 2021-01-02 12:57

    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;
    }
    
    0 讨论(0)
  • 2021-01-02 13:22

    From Controller you can do this

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

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

    0 讨论(0)
提交回复
热议问题