cari
Rumahphp教程php手册CodeIgniter源码阅读URI.php中

APPPATH/config/config.php中对于url 格式的拟定。 $config['uri_protocol'] = 'AUTO'; 这个配置项目定义了你使用哪个服务器全局变量来拟定URL。 默认的设置是auto,会把下列四个方式轮询一遍。当你的链接不能工作的时候,试着用用auto外的选项。 'AUTO' Def

APPPATH/config/config.php中对于url 格式的拟定。
$config['uri_protocol']    = 'AUTO';

这个配置项目定义了你使用哪个服务器全局变量来拟定URL。
默认的设置是auto,会把下列四个方式轮询一遍。当你的链接不能工作的时候,试着用用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
 
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

 

获取到的current uri string 赋值到 $uri_string ,通过function _set_uri_string($str)。

 

获取到$str有几个选项,也就是_fetch_uri_string()的业务流程部分了

一、默认$config['uri_protocol'] = 'AUTO'时,程序会一次轮询下列方式来获取URI

(1)当程序在CLI下运行时,也就是在命令行下php文件时候。ci会这么获取URI
    

private function _parse_cli_args()
        {
            $args = array_slice($_SERVER['argv'], 1);
            return $args ? '/' . implode('/', $args) : '';
        }

   //$_SERVER['argv'] 包含了传递给脚本的参数 当脚本运行在CLI时候,会给出c格式的命令行参数
   截取到$_SERVER['argv']中除了第一个之外的所有参数
   

如果你在命令行中这么操作

php d:\wamp\www\CodeIgniter\index.php\start\index

    _parse_cli_args() 返回一个 /index.php/start/index的字符串

  (2)默认使用REQUEST_URI来探测url时候会调用 私有函数  _detect_uri()

   (3)如果上面的两种方式都不能获取到uri那么会采用$_SERVER[‘PATH_INFO’]来获取

$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
			if (trim($path, '/') != '' && $path != "/".SELF)
			{
				$this->_set_uri_string($path);
				return;
			}
 (4)如果上面三种方式都不能获取到,那么就使用$_SERVER[‘QUERY_STRING’]或者getenv[‘QUERY_STRING’]
$path =  (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
			if (trim($path, '/') != '')
			{
				$this->_set_uri_string($path);
				return;
			}
  (5)上面四种方法都不能获取到URI,那么就要使用$_GET数组了,没招了
if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
			{
				$this->_set_uri_string(key($_GET));
				return;
			}
二、在config.php中设定了$config['uri_protocol'] ,那么 程序会自动执行相应的操作来获取uri
Kenyataan
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn

Alat AI Hot

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

AI Hentai Generator

AI Hentai Generator

Menjana ai hentai secara percuma.

Artikel Panas

R.E.P.O. Kristal tenaga dijelaskan dan apa yang mereka lakukan (kristal kuning)
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Tetapan grafik terbaik
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Cara Memperbaiki Audio Jika anda tidak dapat mendengar sesiapa
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Cara Membuka Segala -galanya Di Myrise
4 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌

Alat panas

Muat turun versi mac editor Atom

Muat turun versi mac editor Atom

Editor sumber terbuka yang paling popular

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Persekitaran pembangunan bersepadu PHP yang berkuasa

SublimeText3 versi Cina

SublimeText3 versi Cina

Versi Cina, sangat mudah digunakan

Versi Mac WebStorm

Versi Mac WebStorm

Alat pembangunan JavaScript yang berguna

VSCode Windows 64-bit Muat Turun

VSCode Windows 64-bit Muat Turun

Editor IDE percuma dan berkuasa yang dilancarkan oleh Microsoft