The routes.php usage of codeigniter configuration is analyzed in this paper. Share to everyone for your reference, specific as follows:
An array named $route is defined in application/config/routes.php to set the default route and 404 pages and to set up some matching methods.
The default configuration is as follows:
$route [' default_controller '] = "welcome";
$route [' 404_override '] = ';
DEFAULT_CONTROLLER Specifies the default controller name, 404_override specifies the name of the controller that is invoked when 404 occurs. Sometimes the resolution is unsuccessful, or the default page is always available, and we can call $this->router to print out the currently resolved controller and acion name. For example, you can print the following in My_controller:
Var_dump ($this->router->fetch_directory ());
Var_dump ($this->router->fetch_class ());
Var_dump ($this->router->fetch_method ());
Determine which controller to resolve under, and then look at the URL configuration, server configuration, and can be debugged in router.php and uri.php.
$route arrays can also be set to override rules by wildcard characters (: num, any), and the following are some simple examples:
1, the http://pc.local/admin/detail_1.htm request resolution to http://pc.local/admin/detail.htm?user_id=1 processing.
CodeIgniter does not support overriding rules that contain query strings, and this rule should look like this:
Copy Code code as follows:
$route [' Admin/detail_ (: num) '] = ' admin/detail?user_id=$1 ';
But actually not effective, the program matching to admin/detail?user_id=1 after the "/" separated, the index of 0 for the controller name, index 1 for the method name, that is, will assign the above detail?user_id=1 to the method name, the result can be imagined 404. After figuring out the principle of separation, you can add a slash behind the detail to ensure that the class name and method name are correct, such as:
Copy Code code as follows:
$route [' Admin/detail_ (: num) '] = ' admin/detail/?user_id=$1 ';
However, there is also the problem of obtaining parameters, the third parameter is passed to the method, if you need to use $_get or $this->input->get fetch also need to process the parameters, such as:
Copy Code code as follows:
Parse_str (LTrim ($query _string, '? '), $_get);
2, the Path_info URL form rewrite rules or more support. To implement HTTP://PC.LOCAL/ADMIN/1 this format:
Copy Code code as follows:
$route [' admin/(: num) '] = ' admin/detail/$1 ';
The argument can only be obtained by means of a paragraph.
Note: Routes will run in the order that they are defined. High-level routing always takes precedence over low-level routes.
Finally, the route that can be set using CI is recommended for use with CI to set, not dependent on server configuration.
More about the CodeIgniter framework interested readers can view the site topic: "CodeIgniter Introductory Course"
I hope this article will help you with the PHP program design based on CodeIgniter framework.