【发布时间】:2013-03-29 02:45:53
【问题描述】:
我有一个基本控制器 (base),所有其他控制器都从该控制器扩展。
放在这里的任何东西都会覆盖其他控制器,重定向会在这里。
网址示例:
http://domain.com/controllerone/function
http://domain.com/controllertwo/function
http://domain.com/controllerthree/function
使用下面的代码。会给我控制器名称
$this->uri->segment(1);
上述每个控制器都需要重定向到单独的 URL,但功能部分不应该改变:
http://domain.com/newcontrollerone/function
http://domain.com/newcontrollertwo/function
http://domain.com/newcontrollerthree/function
在我的基本控制器中,我想要以下逻辑:
$controller_name = $this->uri->segment(1);
if($controller_name === 'controllerone'){
// replace the controller name with new one and redirect, how ?
}else if($controller_name === 'controllertwo'){
// replace the controller name with new one and redirect, how ?
}else{
// continue as normal
}
我在想我应该使用redirect() 函数和str_replace(),但不知道它们的效率如何。理想情况下,我不想使用Routing 类。
谢谢。
【问题讨论】:
标签: codeigniter url redirect