代码点火器404_override
中设置了 $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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你对这一切的看法都是错误的。在你的交换机内部,不要包含其他不起作用的控制器,而是使用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.