![](/img/trans.png)
[英]How to redirect url when controller function argument is empty in codeigniter?
[英]Browser URL not changing when redirect to default controller , Codeigniter
嗨,我正在使用codeigniter,當我在瀏覽器中鍵入基本URL時,我想重定向到默認控制器。
我的基本網址
http://localhost/itams/index.php
我的默認路線
$route['default_controller'] = "new_starter/listing";
我的問題是,當我在瀏覽器中鍵入http://localhost/itams/index.php
時,它正確地重定向到new_starter/listing
頁面,但瀏覽器URL並未更改。 它顯示為http://localhost/itams/index.php
。
這是默認行為嗎?
如何更改瀏覽器URL?
我是否必須使用
header()
進行手動重定向?
提前致謝 。
這是默認行為嗎?
答。 - 是的
如何更改瀏覽器URL?
您需要將此代碼放在默認控制器方法的開頭
if($this->uri->total_segments() === 0){
redirect('controller/method','refresh');
}
即在您的情況下, new_starter
控制器的listing
方法。
最終應該看起來像這樣
Class New_starter extends APP_Controller {
...
public function listing(){
if($this->uri->total_segments() === 0){
redirect('new_starter/listing','refresh');
}
// rest of your method code.
}
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.