codeigniter 404_override

时间:2011-04-15 15:16:27

标签: codeigniter codeigniter-url

我设置了$ routes ['404_override'] ='city / switch_site'

现在在我的城市控制器

class City扩展了CI_Controller {

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

    function switch_site( ) {
        $this->load->helper('url'); // load the helper first
        $city = $this->uri->segment(1);
        $segment_cnt = 1;
        $valid_url = '';

        switch( $city ) {

            case 'pune':
                        $segments = $this->uri->segment_array(2);
                        foreach($segments as $value) {
                            if($segment_cnt > 1) {
                                $valid_url .= $this->uri->slash_segment($segment_cnt);
                            }
                            $segment_cnt++;
                        }
                        $this->config->set_item('cityid',1);
                        $this->config->set_item('cityname','pune');
                        echo APPPATH.'controllers/'.$valid_url;
                        include_once(APPPATH.'controllers/'.$valid_url);
                        break;
            case 'mumbai':
                        $segments = $this->uri->segment_array(2);
                        foreach($segments as $value) {
                            if($segment_cnt > 1) {
                                $valid_url .= $this->uri->slash_segment($segment_cnt);
                            }
                            $segment_cnt++;
                        }
                        $this->config->set_item('cityid',2);
                        $this->config->set_item('cityname','mumbai');
                        include_once(APPPATH.'controllers/'.$valid_url);
                        break;
            default:


        }
    }
}

我现在如何将正确的url传递给codeigniter路由器

1 个答案:

答案 0 :(得分:0)

我认为你这一切都是错的。在你的交换机内,而不是包括其他无法工作的控制器,使用redirect()将它们带到应该去的地方。