在 CakePHP 中保留父级 slugs
我正在尽可能高效地在 CakePHP 中尝试 SEO 友好的 URL,我已经设法使用当前格式,每个示例都使用函数 view($slug),除了第一个示例使用函数 index()。
/类别/
/类别/书籍/
/categories/books/it-and-computing/
但是如果 IT 与计算又会怎样呢?计算有一个子类别“Web 开发”?我希望网址变成:
/categories/books/it-and-computing/web-development/
我不知道如何在不创建太多路线的情况下做到这一点。这是到目前为止我的路线代码:
Router::connect('/categories/', array('controller' => 'categories', 'action' => 'index'));
路由器::connect('/categories/:slug', array('控制器' => '类别', '操作' => '视图'), 数组('pass' => 数组('slug')) );
路由器::connect('/categories/:parent/:slug', array('控制器' => '类别', '操作' => '视图'), array('pass' => array('parent', 'slug')) );
任何帮助将不胜感激
亲切的问候
斯蒂芬
I'm experimenting with SEO friendly URL's in CakePHP as efficiently as I can, I've managed to use the current format, each example uses function view($slug) except for the first example which uses function index().
/categories/
/categories/books/
/categories/books/it-and-computing/
But what if IT & Computing has a sub-category "Web Development"? I'd like the URL to become:
/categories/books/it-and-computing/web-development/
I'm not sure how to do this without creating too many routes. Here is my route code so far:
Router::connect('/categories/', array('controller' => 'categories', 'action' => 'index'));
Router::connect('/categories/:slug',
array('controller' => 'categories', 'action' => 'view'),
array('pass' => array('slug'))
);Router::connect('/categories/:parent/:slug',
array('controller' => 'categories', 'action' => 'view'),
array('pass' => array('parent', 'slug'))
);
Any help would be greatly appreciated
Kind Regards
Stephen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
/categories/books/computing/web-development/cakephp/
结果:
/categories/
结果:
/categories/books
结果:
/categories/books/computing/web-development/cakephp/
result:
/categories/
result:
/categories/books
result: