Zend框架路由器默认用破折号替换大写字母?
如果我们在 zend 控制器的名称和操作之间使用大写字母,例如在我们创建的默认模块中,
class MyGoodController extends Zend_Controller_Action {
public fooBarAction()
{
}
}
则访问此操作的浏览器 url 看起来像 mysite.com/my-good/foo-bar
zf 管理中是否添加了任何默认的 zend 路由器这个翻译? 因为我想使用 URL 视图助手为我生成正确的链接,但它不生成正确的链接,例如在视图中
$this->url(array('action'=>'fooBar','controller=>'myGood'));
没有生成正确的 url,它生成 /myGood/fooBa
r 而不是 /my-好/foo-bar
If we use capital alphabet in between name for zend controller and action for example inside default module we create
class MyGoodController extends Zend_Controller_Action {
public fooBarAction()
{
}
}
Than to access this action browser url looks like mysite.com/my-good/foo-bar
Is there any default zend router added inside zf managing this translation ?
because I want to use URL view helper to generate the correct link for me which it doesnt for e.g in view
$this->url(array('action'=>'fooBar','controller=>'myGood'));
did not produce the correct url it generates /myGood/fooBa
r instead of /my-good/foo-bar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您需要使用的评论中所述:
URL 视图助手根据应用程序中设置的路由来组装链接。
根据URL路由匹配请求。
这实际上归结为关注点分离。助手仅使用路由,并且路由仅处理 URL 中的内容。根据路线获取正确的类名称是调度员关心的问题。
最好让路由只处理 URL 中的内容,因为调度程序可能会更改。使用标准调度程序对您有用的方法可能不适合使用不同调度程序的其他人。
为了完成您所要求的任务,您始终可以使用自定义视图助手来为您进行转换,但前提是您从不更改调度程序。
As stated in the comment you need to use:
The URL view helper assembles a link based on a route set in your application.
Routes match requests based on the URL.
It really comes down to separation of concerns. The helper is only making use of a route and again routes only deal with what is in the URL. Getting the proper class names based on a route is the dispatcher's concerns.
It's best to leave the route to deal with only what is in the URL because dispatchers can change. What might work for you using the standard dispatcher may not fit others that use a different dispatcher.
To accomplish what you're asking, you can always use a custom view helper that does the conversion for you but that is assuming you never change dispatchers.