CI Framework source code interpretation of uri.php _fetch_uri_string () function usage Analysis _php instance

Source: Internet
Author: User
Tags codeigniter zend framework

This article illustrates the use of _fetch_uri_string () function in CI framework uri.php. Share to everyone for your reference, specific as follows:

apppath/config/config.php in the URL format.

$config [' uri_protocol '] = ' AUTO ';

This configuration project defines which server global variable you use to develop URLs.
The default setting is auto, which polls the following four ways. When your link is not working, try using an option outside of auto.

' AUTO ' Default-auto detects
' Path_info ' Uses the Path_info
' Query_string ' Uses the Query_string
' Request_uri ' Uses the Request_uri
' Orig_path_info ' Uses the Orig_path_info

Several member variables in the Ci_uri

$keyval = Array (); List of  cached URI segments
$uri _string//current  uri string
$segments//list of  URI segments
$rsegments = Array ()//re-indexed  List of URI segments

Gets the current URI string assigned to the $uri _string, through the function _set_uri_string ($STR).

There are several options for getting to $str, that is, the business process section of _fetch_uri_string ()

First, the default

$config [' uri_protocol '] = ' AUTO '

, the program polls the following methods at once to get the URI

(1) When the program is running under the CLI, that is, the php file at the command line. CI will get the URI so

Private Function _parse_cli_args ()
{
  $args = array_slice ($_server[' argv '), 1);
  Return $args? '/'. Implode ('/', $args): ';
}

$_server[' argv ' contains parameters that are passed to the script when the script runs in CLI, it gives the command line arguments in c format

Intercept all parameters except the first one in $_server[' argv '

If you do this on the command line,

PHP D:\wamp\www\CodeIgniter\index.php\start\index

_parse_cli_args () returns a/index.php/start/index string

(2) The default use of Request_uri to detect URLs will call the private function _detect_uri ()

(3) If the above two methods can not obtain the URI, then the $_server[' Path_info ' will be used to obtain

$path = (isset ($_server[' path_info '))? $_server[' Path_info '  : @getenv (' path_info ');
if (Trim ($path, '/')  != ' && $path!= '/'. SELF)
{
  $this->_set_uri_string ($path);
  return;
}

(4) If none of the above three ways can be obtained, then use

$_server[' query_string '] or getenv[' query_string '

$path = (isset ($_server[' query_string '))? $_server[' query_string ': @getenv (' query_string ');
if (Trim ($path, '/')!= ')
{
  $this->_set_uri_string ($path);
  return;
}

(5) The above four methods can not get to the URI, then it is necessary to use the $_get array, no strokes

if (Is_array ($_get) && count ($_get) = = 1 && trim (key ($_get), '/')!= ')
{
  $this->_set_uri_ String (Key ($_get));
  return;
}

Second, in the config.php set the:

$config [' Uri_protocol ']

Then the program automatically performs the appropriate action to get the URI

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.