_remap () usage in CodeIgniter Framework 2 examples _php Tutorial

Source: Internet
Author: User
First, CodeIgniter manual related introduction
The second fragment of the URI determines which method in the controller is called. CodeIgniter allows you to use the _remap () method to repeal this rule:
Copy CodeThe code is as follows: Public function _remap ()
{
Some code here ...
}
Note: If your controller contains a method named _remap (), it will always be ignored regardless of what your URI contains. This method will eliminate the rule that determines which method is called by the URI fragment, allowing you to redefine the rules that invoke the method (the routing rules for the method).
You can call the _remap () method by Example.com/index.php/blog/To call the specific code if the _remap () parameter is added to the/post parameter.
Ii. Methods of Use 2 cases
But the question is, what is the use of that in the handbook? In fact, there are two of useful:

1, change the URL, hidden methods, such as your application, the original URL method is:
Copy the Code code as follows: Example.com/index.php/blog/say
Now you want to change the display method named:
Copy the Code code as follows: Example.com/index.php/blog/hello
But although the display is Hello, it is actually called the Say method that exists
2, you can also use this function to do a simple function method permission control, such as:
Copy the Code Code 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 take the user session in the level $user _type, and then check the method validate_access This user has no permission to call this method ($method), if there is $access_control==true, Otherwise, an error message is displayed.

http://www.bkjia.com/PHPjc/739777.html www.bkjia.com true http://www.bkjia.com/PHPjc/739777.html techarticle I. CodeIgniter manual about the second fragment of the URI determines which method in the controller is called. CodeIgniter allows you to use the _remap () method to repeal this rule: Copy the Code ...

  • 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.