In Codeigniter, there is actually a good way to handle controller layers that are easy to ignore,
This is remap. Here is a brief introduction.
In fact, in the ci url control mode representation, for example:
Example.com/index.php/blog/comments/
In this form, the blog is the controller, and the comments is your method.
For example, the parameter transmission is as follows:
Example.com/index.php/products/shoes/sandals/123
Sandals/123 is the two parameters passed.
The second segment of URI determines the method in the controller. CodeIgniter allows you to use the _ remap () method to abolish this rule:
Public function _ remap ()
{
// Some code here...
}
NOTE: If your controller contains a method named _ remap (), it will be ignored no matter what the URI contains. This method will abolish the rule that the URI fragment determines which method is called and allow you to redefine the rule for calling the method (the routing rule of the method ).
But the question is, what is the use of this in the manual? In fact, there are two functions:
1. Change the URL and hide the method. For example, in your application, the original URL method is:
Http://anmsaiful.net/blog/display_successful_message
Now you want to change the display method name:
Http://anmsaiful.net/blog/successful
However, although it is successful, it is actually the display_successful_message that exists in the call.
The _ remap method is required.
2. You can also use this function for simple function method control, such:
Public function _ remap ($ method, $ params = array ())
{
$ User_type = $ _ SESSION ['user _ type'];
$ Access_control = $ this-> validate_access ($ user_type, $ method );
If ($ access_control ){
$ This-> $ method ();
}
Else {
$ This-> show_message ();
}
}
First retrieve the level $ user_type in the user session, and then check the Pass Method
Validate_access whether the user has the permission to call this method ($ method)
If yes, $ access_control = true; otherwise, the error message is displayed.
From jackyrong