Home  >  Article  >  Backend Development  >  2 examples of how to use remap() in the CodeIgniter framework_PHP tutorial

2 examples of how to use remap() in the CodeIgniter framework_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:36:20901browse

1. Introduction to CodeIgniter manual
The second fragment of the URI determines which method in the controller will be called. CodeIgniter allows you to use the _remap() method to abolish this rule:

Copy code The code is as follows:
public function _remap()
{
// Some code here...
}

Note: If your controller contains a method named _remap(), no matter what your URI contains What, it will always be ignored. This method removes the rule that URI fragments determine which method is called, allowing you to redefine the rules for calling methods (method routing rules).
You can call the _remap() method through example.com/index.php/ blog / . If _remap() has parameters, add parameters after / to call the specific code.
2. 2 examples of usage
But the question is, if the manual says this, what is the use of it? In fact, it has two uses:

1. Change the URL and hide the method. For example, in your application, the original URL method is:

Copy the code The code is as follows:
example.com/index.php/blog/say

Now the method you want to change the display is named:
Copy the code The code is as follows :
example.com/index.php/blog/hello

But although the display is hello, it actually calls the existing say method
2. You can also use this function to do it Simple function method permission control, such as:
Copy code 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{
else{ $this->show_message();
}
}
First remove the user Level $user_type in the session, and then check whether the user has permission to call this method ($method) through the method validate_access. If so, $access_control==true, otherwise an error message will be displayed.

http://www.bkjia.com/PHPjc/739777.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/739777.htmlTechArticle1. Related introduction to CodeIgniter manual The second fragment of the URI determines which method in the controller will be called. CodeIgniter allows you to override this rule using the _remap() method: Copy code...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn