我希望使我的url更加符合seo优化要求。将
我解决了这个问题。
www.example.com/posts/view/1
改为www.example.pl/:slug-:id
。一切工作正常,但可能我的路由设置有误,因为当在paginator中点击urls后,url是正确的,看起来像www.example.pl/:slug-:id
,但是却出现了错误:
"The requested address 'www.example.pl/:slug-:id' was not found on this server."
我不知道问题出在哪里。这是我的代码:
Router::connect(
'/:slug-:id',
array(
'controller' => 'posts',
'action' => 'view'
),
array(
'pass' => array('slug' , 'id'),
'id' => '[0-9]+'
)
);
在分页器视图中:
echo $this->Html->link($ad['Post']['title'], array(
'controller' => 'posts',
'action' => 'view',
'slug' => Inflector::slug($post['Post']['title'],'-'),
'id'=>$post['Post']['id'])
);
我解决了这个问题。
public function view($slug,$id){
. - AD7six