Is there a simple way to route my URLs without showing the ID in the URL. For example i have:
开发者_JAVA技巧www.mywebsite.com/id-article-title.html and i want only www.mywebsite.com/article-title.html
Regards
Add a url column to your db table. Then you can do findByUrl()
. As noted above it's well documented.
function view($url = null) {
if (!$url) {
$this->Session->setFlash('Invalid url');
$this->redirect(array('action'=>'index'));
}
$this->set('something', $this->Something->findByUrl($url));
}
You can create beforeSave
methods to process your urls for uniqueness an uuencoding.
You can eliminate the need to specify www.domain.com/controller/view/latest-news
using routes like:
Router::connect('/*', array('controller' => 'somethings', 'action' => 'view'))
Now www.domain.com/latest-news
will return the same page.
Haven't tried this one but I think the link below may help you somewhat
adding friendly urls to the cake application
using url slugs in cakephp
精彩评论