我有一個所有其他控制器擴展的基礎控制器(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