2013-02-22 27 views
3

我的代碼點火器路由文件中有如下路由。帶尾部斜線的URL導致不同的頁面 - MVC CI

$route['profile'] = "profile"; 

類配置文件包含以下

$this->load->view('pages/profile.php'); 

現在我有一個類似如下

<a href = 'logout'>Logout</a> 

現在考慮使用它用戶我profile.php頁面上的鏈接。如果他現在訪問以下網址

localhost/project/profile 

然後profile.php頁面上的鏈接會導致以下

localhost/project/logout 

但是,如果用戶使用此URL

localhost/project/profile/ 

那如果存在斜線,則頁面上的鏈接將導致

localhost/project/profile/logout 

現在我的問題是我應該做在這兩種情況下的鏈接導致

localhost/project/logout 

希望我是清楚的。請幫我出

+0

爲什麼不使用codeingiter url helper? Logout 2013-02-22 15:14:30

+0

@FabioAntunes幫助。謝謝。任何來到這裏的人都會發現這個網址很有用 - http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html – Srivathsan 2013-02-22 15:19:32

回答

1

我認爲你正在尋找這一點,只要你想呼應的URL使用此代碼,此代碼行

$this->load->helper('url'); 

加載網址助手控制器上你的看法

//this will echo something like this http://(yourdomain).index.php/logout 
<a href = '<?=site_url("logout")?>'>Logout</a> 

如果你想要讓我們說,一個URL到另一個控制器時,你會使用這樣的

//this will echo something like this http://(yourdomain).index.php/(anothercontroller)/logout 
<a href = '<?=site_url("anothercontroller/logout")?>'>Logout</a> 

有關來自codeigniter的url幫手的更多信息可以在這裏找到: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

相關問題