2015-02-10 34 views
-2
除去ID

我的當前URL爲
http://localhost/news/user/user_profile/16如何從URL中笨

http://localhost/news =是基本URL

/用戶/ =被控制器名稱

user_profile =是函數名

這是鏈接

<a href="<?php echo base_url().'user/user_profile/'.$id;?>" class="btn btn-default btn-flat">Profile</a> 

16 =是用戶ID

我想從URL刪除用戶ID

,所以我想我的網址這樣

http://localhost/news/user/user_profile

請幫助......

+0

沒有用戶ID你如何訪問相應的頁面? – Arun 2015-02-10 04:48:21

+0

問題在哪裏?只需從您的鏈接中刪除«。$ id»。 – Joerg 2015-02-10 04:48:30

+0

你可以使用if語句'uri segment' 3是true,然後顯示url或者顯示user_profile。 – user4419336 2015-02-10 04:56:32

回答

0

這取決於你使用的方式。

如果你想顯示自己的配置文件或登錄用戶配置文件。 您可以使用該鏈接。 http://localhost/news/user/user_profile 其中id將是會話中記錄的用戶ID ..

在其他情況下,如果您想顯示其他用戶的個人資料,如Facebook個人資料。您必須在網址中輸入id或slug。這是最好的方法。

http://localhost/news/user/user_profile/(id)http://localhost/news/user/user_profile/(slug-name)

你仍然需要有一個像http://localhost/news/user/user_profile/ URL意味着你必須使用形式爲每一個環節,並提交形式爲每個請求,並把ID爲POST方法,我將不建議的方式。