簡體   English   中英

CakePHP,是否可以在網址前面使用記錄ID

[英]CakePHP, Is it possible to use a record id in the front of the url

我需要在所有頁面的URL中設置記錄ID。 例如,如果用戶不提供ID,則網站應始終使用1000作為默認值,例如 http:// www.demosite.com/1000。

如果用戶導航到http:// www.demosite.com/1001,則在會話中設置記錄1001詳細信息並將其顯示在元素中。 從這里開始,我需要所有網址看起來像這樣。

http:// www.demosite.com/1001/about-us

http:// www.demosite.com/1001/wizard/step1

http:// www.demosite.com/1001/prices/view/1

我已經嘗試了下面的路由,該路由可以工作,但是我需要重定向,然后我在URL中丟失了1001記錄ID。

Router::connect('/:id', array('controller' => 'distributors', 'action' => 'session'), array('id' => '[0-9]+'));
Router::connect('/:id/**', array('controller' => 'distributors', 'action' => 'session'), array('id' => '[0-9]+'));

有人可以幫我嗎?

您把它弄復雜了,只需要在控制器的方法中傳遞它,在那定義1000個默認值,然后再定義其他參數即可。

function index($id=1000){

}

當您將新的id傳遞給將覆蓋新的id的方法時

除此之外,您還可以使用htaccess來處理其他網址位置,例如

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^([0-9]{6})$ scriptname.php?no=$1 [L]
</IfModule>

您可以從http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html尋求幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM