How to use _ remap () in CodeIgniter framework 2 examples _ PHP Tutorial

Source: Internet
Author: User
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 :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.