使用 Zend Router 提供对 Seo 友好的 url
我想在我的 Zend Framework 应用程序中创建 seo 友好的 url,但是正确的语法是怎样的:
$newsroute = new Zend_Controller_Router_Route(
'news/:action/:id_:title',
array( 'controller' => 'news' ));
:id_:title 显然不起作用,因为 Zend 不知道 _ 是分隔符?我是否需要使用正则表达式路由器来实现此目的,或者它也可以与普通路由器一起使用吗?
I want to create seo friendly urls in my Zend Framework application but how is the correct syntax for this:
$newsroute = new Zend_Controller_Router_Route(
'news/:action/:id_:title',
array( 'controller' => 'news' ));
:id_:title obviously doesn't work since Zend didn't know that _ is a separator? Do i need to use the regex router for this or does it work with the normal one too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,正则表达式路线就可以做到这一点。
如果出于某种原因您不想使用正则表达式路由,可以通过前端控制器插件实现一个简单的解决方法:
当然,如果需要,您也可以以相同的方式提取标题。
当你想生成 url 时,不要忘记构建你的 'article' 参数:
Indeed a regex route would do the thing.
If for any reason you don't want to use the regex route, there is a simple workaround via a front controller plugin:
Of course you can also extract the title the same way if you need it.
Don't forget to build your 'article' param when you want to generate urls:
为了避免处理包含特殊字符的链接,您可以使用 Zend Framework 的此插件。
https://github.com/btlagutoli/CharConvert
这可以帮助您处理其他语言的字符串
To avoid dealing with the links contain special characters, you can use this plugin for Zend Framework.
https://github.com/btlagutoli/CharConvert
this can help you deal with strings in other languages