zoukankan      html  css  js  c++  java
  • CodeIgniter_2 路由中定义伪静态 直接映射到相关的控制器

    某些情况下 隐藏路径信息 使用伪静态定义:

    RewriteRule ^no/torrent(.*)$ /index.php/torrent/doit/$1

    CodeIgniter会自动识别到 no 控制器,但是我其实想识别到 torrent 控制器 

    需要对 coreURI.php 文件进行处理下

    	/**
    	 * Detects the URI
    	 *
    	 * This function will detect the URI automatically and fix the query string
    	 * if necessary.
    	 *
    	 * @access	private
    	 * @return	string
    	 */
    	private function _detect_uri()
    	{
    		if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
    		{
    			return '';
    		}
    
    		$uri = $_SERVER['REQUEST_URI'];
    
    		//添加的数据 重新定义url
            if(isset($_SERVER['PHP_SELF'])){
    	        if($_SERVER['PHP_SELF'] != '' and $_SERVER['PHP_SELF'] != $_SERVER['REQUEST_URI']){
    		        $uri = $_SERVER['PHP_SELF'];
    		        if(isset($_SERVER['QUERY_STRING']) and $_SERVER['QUERY_STRING'] != ''){
    			        $uri = $uri.'?'.$_SERVER['QUERY_STRING'];
    		        }
    	        }
            }
            //来自 吠品 http://www.cnblogs.com/osfipin/
    
    		
    		if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
    		{
    			$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
    		}
    		elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
    		{
    			$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
    		}
    
    		// more
    	}
    

      CodeIgniter 3.0 对 这个文件进行了重构。想实现这个需求 貌似也不行,大家可以测试一下子。

  • 相关阅读:
    Ubuntu下配置Viw Tab键缩进格数
    Windows文件传给Ubuntu出现乱码问题
    [Luogu] P4948 数列求和
    [Luogu]P1286 两数之和
    [Luogu]P2717 寒假作业
    [Luogu]P5110 块速递推
    Breeze魔兽编程交流论坛
    #pragma 预处理指令详解
    Api Hook 细析(一)
    CMS(网站内容管理系统)有哪些?
  • 原文地址:https://www.cnblogs.com/osfipin/p/4548833.html
Copyright © 2011-2022 走看看