我在我的一个项目中使用 cakephp,我的客户希望网站 URL 以 .html 结尾,而不是通常的友好 URL。我想知道在 cakephp 中是否有可能通过它的任何路由技术来做到这一点。请帮忙。
最佳答案
这在 cookbook 中有详细记录.
更新:http://book.cakephp.org/2.0/en/development/routing.html#file-extensions
To handle different file extensions with your routes, you need one extra line in your routes config file:
Router::parseExtensions('html', 'rss');
If you want to create a URL such as /page/title-of-page.html you would create your route as illustrated below:
Router::connect(
'/page/:title',
array('controller' => 'pages', 'action' => 'view'),
array(
'pass' => array('title')
)
);
Then to create links which map back to the routes simply use:
$this->Html->link(
'Link title',
array('controller' => 'pages', 'action' => 'view',
'title' => 'super-article', 'ext' => 'html')
);
关于php - 如何将 .html 附加到 cakephp 中的所有 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3410611/