发新话题
打印

让 CodeIgniter 支持 $_GET

本主题由 Hex 于 2008-7-27 02:13 加入精华

让 CodeIgniter 支持 $_GET

CI默认过滤了$_GET

需要传递get参数时一般直接 /参数一/参数二
详见手册说明:http://codeigniter.org.cn/user_guide/general/controllers.html#passinguri

但是有时候需要传递很长的复杂的url,比如常用的 http://www.nicewords.cn/index.php/controller/method/?backURL=http://baidu.com/blog/hi

这时 这种模式就行不通了。参数中本身的/会与默认的分隔符冲突

解决方案

1) 在config.php 中,将‘uri_protocol’ 设置为 ‘PATH_INFO’.
$config['uri_protocol'] = "PATH_INFO";


2) 在需要使用$_GET的之前加:

parse_str($_SERVER['QUERY_STRING'],$_GET);

这样,形如 index.php/blog/list?parm=hello&page=52 就可以运行了。

官网说明:
http://codeigniter.com/wiki/QUERY_STRING_GET/
本帖最近评分记录
  • Hex 威望 +5 精品文章 2008-6-16 18:24

TOP

很不错,支持楼主!!!

TOP

好文章,支持.
:victory:

TOP

parse_str
php自身的函数很顶....

TOP

:lol :lol :lol :lol :lol

TOP

顶一下 不错的方法。:handshake

TOP

好方法。。顶。。。。
专注ria,flex,extjs,jquery
男がどんな理屈を并べても、女の涙一滴にはかなわない
http://www.girlsgroup.cn

TOP

我在官網討論區看到一篇很不錯的解法   http://codeigniter.com/forums/viewthread/68698/#389281
他只有二個步驟

1.config.php的設定
   $config['uri_protocol']    = "REQUEST_URI";
   $config['enable_query_strings'] = TRUE;


2.將以下程式存檔,檔名叫MY_URI.php
   存檔路徑    自己的system/application/libraries/ folder
复制内容到剪贴板
PHP 代码:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_URI extends CI_URI {

    function MY_URI() {
        parent::CI_URI();
    }

    // --------------------------------------------------------------------
   
    /**
     * Override the _parse_request_uri method so it allows query strings through
     *
     * @access    private
     * @return    string
     */
 
    function _parse_request_uri()
    {
        if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '')
        {
            return '';
        }
       
        $uri = explode("?",$_SERVER['REQUEST_URI']); // This line is added to the original
        $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $uri[0])); // This line changed
        // Everything else is just the same

        if ($request_uri == '' OR $request_uri == SELF)
        {
            return '';
        }
       
        $fc_path = FCPATH;        
        if (strpos($request_uri, '?') !== FALSE)
        {
            $fc_path .= '?';
        }
       
        $parsed_uri = explode("/", $request_uri);
               
        $i = 0;
        foreach(explode("/", $fc_path) as $segment)
        {
            if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i])
            {
                $i++;
            }
        }
       
        $parsed_uri = implode("/", array_slice($parsed_uri, $i));
       
        if ($parsed_uri != '')
        {
            $parsed_uri = '/'.$parsed_uri;
        }

        return $parsed_uri;
    }

}

?>
本帖最近评分记录
  • Hex 威望 +3 精品文章 2008-11-27 12:19

TOP

发新话题