本文介紹了如何將 .html 附加到 cakephp 中的所有 URL?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在我的一個項目中使用 cakephp,我的客戶希望站點 URL 以 .html 結尾,而不是通常的友好 URL.我想知道在 cakephp 中是否可以通過它的任何路由技術來做到這一點.請幫忙.
I am using cakephp in one of my projects and my client wants the site URLs to end with .html and not the usual friendly urls. I was wondering if its possible in cakephp to do so through any of its routing techniques. Please help.
推薦答案
不得不在不使用 Routes 的情況下解決這個問題.保留頁面的默認路由條目:
Had to solve this without using Routes. Kept the default route entry for pages:
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
并在顯示操作中刪除了 .html 擴展名并呈現了相應的視圖:
and in the display action removed the .html extension and rendered the respective view:
preg_replace('/.html$/','',$view);
$this->render(null,'default',$view);
在調用頁面時添加ext"為 .html
While calling the pages added 'ext' to be .html
這篇關于如何將 .html 附加到 cakephp 中的所有 URL?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!