CodeIgniter Route Configuration
Route configuration generally used for remapping URL string. Typically there is a one-to-one relationship between an URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:
In some instances, however, you may want to remap this relationship so that a different class/method can be called instead of the one corresponding to the URL.
Setting your own route configuration rules using following steps:
- Go to your application directory then open routes.php file under config directory( application /config / routes.php ).
- At end of file find
- Specify your own routeing criteria ($route[‘profile/:num’]=‘user/base_info’;)
Note : Routes can either be specified using wildcards or Regular Expressions.
A typical wildcard route might look something like this:
In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to. In the above example, if the literal word “profile” is found in the first segment of the URL, and a number is found in the second segment, the “user” class and the “base_info” method are instead used.
You can match literal values or you can use two wildcard types these are:
- (:num) will match a segment containing only numbers.
- (:any) will match a segment containing any character (except for ‘/’, which is the segment delimiter).
There are three reserved routes:
1) $route[‘default_controller’] = ‘welcome’;
This route indicates which controller class should be loaded if the URI contains no data. In the above example, the “welcome” class would be loaded.
2) $route[‘404_override’] = ‘errors/page_missing’;
This route will tell the Router which controller/method to use if those provided in the URL cannot be matched to a valid route.
3)$route[‘translate_uri_dashes’] = FALSE;
This is not exactly a route but allows you to automatically route controller and method names that contain dashes. ‘-‘ isn’t a valid class or method name character, so it requires translation. When you set this option to TRUE, it will replace ALL dashes in the controller and method URI segments.
Latest posts by Subroto Mondal (see all)
- Installing and Configuring OpenShift: A Step-by-Step Guide for Linux Experts with Terminal Code - February 19, 2023
- Sed Command in Linux with Practical Examples - February 19, 2023
- Rsync Command uses with examples - February 19, 2023