什么是 Route,在哪里以及如何定义它?
我的 zend 应用程序中有几个模块。在我的模块的视图脚本之一上,我创建了一个这样的 URL
$links['create'] = $this -> url(array("controller" => "roles", "action" => "create"), "custom");
,这会带来一个错误,指出“自定义”路线未定义。
什么是路线?在哪里定义它以及如何定义它?
I have several modules in my zend application. On one of the view script of my modules, I created a URL as such
$links['create'] = $this -> url(array("controller" => "roles", "action" => "create"), "custom");
This brings an error, saying Route "custom" is not define.
What is Route? Where to define it and How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的引导文件中,我通过添加以下函数来初始化我的路由
,因为我在我的事件中添加了自定义路由,每当我访问详细信息页面时,我都不必在我的网址中写入 id,所以我的网址将类似于
http://localhost/example/events/detail/3
如果我不添加路由,那么我的网址会像
<一个href="http://localhost/example/events/detail/id/3" rel="nofollow">http://localhost/example/events/detail/id/3
In my bootstrap file i have initialized my routing by adding following function
as i have added the custom route in my events, commentaries whenever i visit detail page i dont have to write id in my url so my url will be like
http://localhost/example/events/detail/3
If i wouldnt have added route than my url would be like
http://localhost/example/events/detail/id/3
Zend Framework 手册有关于路由和路由器的相当不错的文档 ,包括定义路由的几种方法的描述。
在非常基础的层面上,路由既用于将 URL 解析为参数(例如应使用哪个控制器和操作),也用于执行相反的操作:获取参数并生成 URL。
出于您的目的,除非您想要更改 ZF 构建 URL 的方式,否则您只需从
url
调用中删除“自定义”部分即可。The Zend Framework manual has pretty decent documentation about routes and the router, including descriptions of several ways to define routes.
At a very basic level, routes are used both to parse URLs into parameters (like which controller and action should be used), and to do the reverse: take parameters and produce a URL.
For your purposes, unless you want to change how ZF will build your URL, you can just drop the "custom" part off of your
url
call.