Monday 22 August 2016

CodeIgniter _remap function?

CodeIgniter permits you to override its default routing behavior through the use of the _remap() function. As you already knew the second segment of the URI typically determines with function is in the controller get called and it will be passed as a parameter to the _remap() function. So to hide the real method name in the URL you can use _remap() and you can define your own set of routing rules.
If your controller contains a function named _remap(), it will always get called regardless of what your URI contains. It overrides the normal behavior. For example: your URL is http://localhost/index.php/post/index and you do not want to call index for this then you can use _remap() to map new function view instead of index like this.
Any extra segments after the method name are passed into _remap() as an optional second parameter. This array can be used in combination with PHP’s call_user_func_array() to reproduce the CodeIgniter’s default behavior.
we can process your mappings neatly by avoiding multiple if – elseif – else and switch statements ,by defining your methods with prefix(Ex: process) and calling methods dynamically with call_user_func_array() as shown below.

Resources:

  • call_user_func_array(): Call a callback with an array of parameters
  • method_exists(): Checks if the class method exists
  • ucwords(): Uppercase the first character of each word in a string
  • _remap(): override the default behavior of CI’s routing
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

No comments:

Post a Comment

Installation of Drop Box API on Codigniter

As with the YouTube API the first step in getting this sucker setup is getting a developer key by visiting  https://www.dropbox.com/develop...