Routes.php Usage Example Analysis of codeigniter configuration, codeigniterroutes_php tutorial

Source: Internet
Author: User
Tags codeigniter

Routes.php Usage Example Analysis of codeigniter configuration, codeigniterroutes


In this paper, the routes.php usage of codeigniter configuration is analyzed. Share to everyone for your reference, as follows:

An array named $route is defined in application/config/routes.php to set the default route and 404 pages and to set 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 controller name that is called when 404 occurs. Sometimes parsing is not successful, or is always on the default page, we can call $this->router to print 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 is resolved under, and then look at the configuration of the URL, the server configuration, and the ability to debug in router.php and uri.php.

$route arrays can also be set by wildcard characters (: num,: Any) and regular rules, here are some simple examples:

1. Resolve the http://pc.local/admin/detail_1.htm request to http://pc.local/admin/detail.htm?user_id=1 processing.
CodeIgniter does not support rewrite rules that contain query strings, and this rule should look like this:
Copy the code as follows: $route [' Admin/detail_ (: num) '] = ' admin/detail?user_id=$1 ';
But actually does not take effect, the program matches to admin/detail?user_id=1 after the "/" separates, the index is 0 for the controller name, the index is 1 for the method name, namely will the above detail?user_id=1 assigns the value to the method name, the result can imagine 404. After figuring out the separation principle, you can add a slash behind the detail to ensure that the class name and method name are correct, such as:
Copy the code as follows: $route [' Admin/detail_ (: num) '] = ' admin/detail/?user_id=$1 ';
However, there is a parameter acquisition problem, the third parameter will be passed to the method, if you need to use $_get or $this->input->get get also need to handle the parameters, such as:
Copy the Code code as follows: Parse_str (LTrim ($query _string, '? '), $_get);
2. The URL format rewrite rules for PATH_INFO are still relatively supported. To implement HTTP://PC.LOCAL/ADMIN/1 this format:
Copy the code as follows: $route [' admin/(: num) '] = ' admin/detail/$1 ';
The acquisition of parameters can only be obtained by means of a paragraph.

Note: Routes will run in the order they are defined. High-level routing always takes precedence over lower-layer routes.

Finally, the routes that can be set using CI are recommended to be set using CI, and are not dependent on the server configuration.

For more information on CodeIgniter framework related content readers can view this site topic: "CodeIgniter Introductory Tutorial"

It is hoped that this article is helpful to the PHP program design based on CodeIgniter framework.

Articles you may be interested in:

    • A tutorial to implement read-write separation in MySQL usage
    • The method of realizing the master-slave reading and writing separation of Yii
    • thinkphp implementing MySQL read-write detach operation example
    • MySQL read-write separation using PHP
    • SQL SERVER2005 Implementation of database read-Write separation introduction
    • MySQL master-slave synchronization, read and write separation configuration steps
    • MySQL read/write separation (actual combat)
    • MySQL read/write separation (Basic article)
    • Example analysis of session usage of CodeIgniter configuration
    • Case analysis of controller succession problem in CodeIgniter controllers
    • CodeIgniter Read and write separation implementation method detailed

http://www.bkjia.com/PHPjc/1093700.html www.bkjia.com true http://www.bkjia.com/PHPjc/1093700.html techarticle routes.php Usage Example Analysis of CodeIgniter configuration, codeigniterroutes This paper analyzes the routes.php usage of codeigniter configuration. Share to everyone for your reference, specifically as follows: AP ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.