【发布时间】:2011-03-15 18:24:50
【问题描述】:
有没有一种简单的方法来路由我的 URL,而不在 URL 中显示 ID。例如我有:
www.mywebsite.com/id-article-title.html 我只想要 www.mywebsite.com/article-title.html
问候
【问题讨论】:
有没有一种简单的方法来路由我的 URL,而不在 URL 中显示 ID。例如我有:
www.mywebsite.com/id-article-title.html 我只想要 www.mywebsite.com/article-title.html
问候
【问题讨论】:
在您的数据库表中添加一个 url 列。然后你可以做findByUrl()。如上所述,它有据可查。
function view($url = null) {
if (!$url) {
$this->Session->setFlash('Invalid url');
$this->redirect(array('action'=>'index'));
}
$this->set('something', $this->Something->findByUrl($url));
}
您可以创建 beforeSave 方法来处理您的 url 以实现 uuencoding 的唯一性。
您可以消除指定 www.domain.com/controller/view/latest-news 的需要,使用如下路由:
Router::connect('/*', array('controller' => 'somethings', 'action' => 'view'))
现在www.domain.com/latest-news 将返回相同的页面。
【讨论】:
【讨论】: