codeigniter无法获得$ this-> uri->段值

时间:2014-10-23 08:40:15

标签: .htaccess codeigniter url routes remap

我正在尝试创建一个基于网络的Codeigniter,但我在网站上发现问题,我把它放在网上

这是我的.htaccess文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

这是我的配置:

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

这是我的Routes.php

$default_controller = "Front";
$controller_exceptions = array('owner');

$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = '';

这是我的Controller类:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Front extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function _remap($segment_1)
    {       
    $segment_1 = $this->uri->segment(1);
    switch ($segment_1)
     {
        case null:
        case false:
        case '':
        $this->load->library('Facebook_ion_auth');
        if (isset($_GET['code']))
            {
            $this->facebook_ion_auth->login();
            if (!$this->ion_auth->logged_in()){
                $this->index();
            }else{
                $succses='Selamat datang! <b>'.$this->ion_auth->user()->row()->user_display_name.'</b>';
                $content = new Content();
                $content->profil($succses,'');
            }
        }else{

            $url =  $this->uri->segment_array();
            print_r($url);
        }

        break;

        case 'category':
            $this->category();
        break;

        case 'search':
            $content = new Content();
            $content->search();
        break;  

        case 'pesan':
            $content = new Content();
            $content->pesan();
        break;

        case 'daftar':
            $content = new Content();
            $content->daftar();
        break;

        case 'login':
            $content = new Content();
            $content->login();
        break;

        case 'keluar':
            $content = new Content();
            $content->keluar();
        break;

        case 'profil':
            $content = new Content();
            $content->profil();
        break;

        case 'kirimpesan':
            $content = new Content();
            $content->kirimpesan();
        break;

        case 'contact':
            $content = new Content();
            $content->contact();
        break;

        case 'testimoni':
            $content = new Content();
            $content->testimoni();
        break;

        case 'facebook':
            $this->load->library('Facebook_ion_auth');
            $this->facebook_ion_auth->login();
        break;

        case 'img':
            $this->img();
        break;

        default:
        $content = new Content();
        $content->sigle();
        break;
        }
    }                                                                                                       

    public function index()
    {
        $content = new Content();
        $content->home();
    }
}

但它总是在运行 case =&#34;&#34; ,这证明 $ segment_1 = $ this-&gt; URI-&GT;无法检测到段(1); 。或者没有来自uri 1的数据。

$url = $this->uri->segment_array(); 
print_r($url); 

显示DISPLAY EMPTY 如何修复,可以检测到订购网址。或者从URL中获取参数??

1 个答案:

答案 0 :(得分:0)

我不明白你想做什么 但如果你提供你的URI,它会很好

是:// site /或:// site / Front ??

也删除此行

$segment_1 = $this->uri->segment(1);

因为您已将其作为参数发送到_remap函数

请注意,如果您的网址没有类名和功能,请执行以下操作:// site / 在

$this->uri->segment(1)

将等于false,因为url中不存在segment