我有一个所有其他控制器扩展的基础控制器(base
)。 这里放置的任何东西都会覆盖其他控制器,重定向将在这里。Codeigniter - url段替换或重定向
网址例如:
http://domain.com/controllerone/function
http://domain.com/controllertwo/function
http://domain.com/controllerthree/function
使用下面的代码。会给我控制器名称
$this->uri->segment(1);
上述每个控制器都需要被重定向到不同的网址,但funcation部分不应该改变:
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
类。
谢谢。
感谢您的回复,如果这是'重定向($ redirect_url,'刷新');'>>'重定向($ redirect_segments,'刷新');'? – TheDeveloper 2013-04-07 13:18:46
是的,应该是,对不起! – jleft 2013-04-07 13:25:30
对我来说都很好,谢谢 – TheDeveloper 2013-04-08 18:39:23