Today I am going to write a short post about the _remap() function in CodeIgniter which is used to remap the function with Controller.
What is _remap() function?
In CodeIgniter, You can remap function calls with the use of the function in your controller called _remap() method. The remap() function will call every time that the controller is called even if a different function is used.We can say that remap() function will remap URI requests to specific controller functions.CodeIgniter will call the _remap() function before calling any other function.
This function is very useful to the developers who want to easily remap the function calls or to remap functions instead of extending a routing class of CodeIgniter.
You can alter the default way by including this function in the controller.
SYNTAX:
1 2 3 | _remap($function) |
Where $function is the name of the function you want to intercept and redirect. _remap always gets called first, whatever the URL says.
Let’s see how _remap() function works in CodeIgniter
1 2 3 4 5 6 7 8 9 10 11 12 13 | function _remap($function) { if($function == "function_name") { $this->$function(); } else { $this->default_function(); } } |
Generally, First parameter in the URL of Codeigniter defines the name of the controller and the second parameter defines the function to be called.Usually, The second segment of the URI will be passed as a parameter of the _remap() function.The default_controller route identifies that which controller should be loaded if no controller is identified.
You can remap the function calls by using the _remap function in your controller in CodeIgniter. This function will be called everytime controller called even if the different function is used. This function is very helpful for developers who want to remap function call to provide different Uniform Resource Identifier (URI) structure or to remap functions instead of extending the routing class of CodeIgniter.
By the end, I suggest you try, How to Get IP address in CodeIgniter and Image Upload in CodeIgniter.
I hope you have enjoyed this short post. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (1)