代码点火器404_override

发布于 2024-11-02 03:06:21 字数 1870 浏览 0 评论 0原文

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

我现在已经在我的城市控制器

类 City extends 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 路由器

I have set the $routes['404_override'] = 'city/switch_site'

now in my city controller

class City extends 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:


        }
    }
}

how do i now pass the correct url to codeigniter router

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-11-09 03:06:21

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

I think you are going about this all wrong. Inside your switch instead of including other controllers which will not work use the redirect() to take them where they should go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文