In the CodeIgniter framework, _ remap () is used in two cases. I. CodeIgniter manual describes the second segment of URI to determine which method in the controller will be called. CodeIgniter allows you to use the _ remap () method to abolish this rule: Copy the code
I. INTRODUCTION to CodeIgniter manual
The second segment of URI determines the method in the controller. CodeIgniter allows you to use the _ remap () method to abolish this rule:
The code is as follows:
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 ).
You can use example.com/index.php/blog/to call the _ remap () method. if _ remap () has a parameter, add a parameter after/to call the specific code.
2. Method 2
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:
The code is as follows:
Example.com/index.php/blog/say
Now you want to change the display method name:
The code is as follows:
Example.com/index.php/blog/hello
However, although it is "hello", it actually calls the existing say method.
2. you can also use this function for simple function method permission control, such:
The code is as follows:
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 whether the user has the permission to call this method ($ method) through the validate_access method. If yes, $ access_control = true, otherwise, the error message is displayed.
The second segment of the URI determines the method in the controller. CodeIgniter allows you to use the _ remap () method to abolish this rule :...