2013-02-22 40 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