用于 ajax API 的 Zend-Route
我正在尝试向我的应用程序添加一条路由,以便我可以将它与 ajax 调用一起使用。
这是我的 application.ini 中的内容
;Routes
resources.router.routes.products.route = "/backend/api/:command"
resources.router.routes.products.defaults.module = "backend"
resources.router.routes.products.defaults.controller = "api"
resources.router.routes.products.defaults.action = "index"
当对 /backend/api/SomeCommand 进行 ajax 调用时,会产生以下错误:
消息:指定的控制器(后端)无效
array (
'controller' => 'backend',
'action' => 'maestro',
'module' => 'default',
)
,如您所见,模块已设置为“默认” ”,而不是“后端”,并且控制器是“后端”而不是“api”,这可能是什么原因造成的?
I'm trying to add a route to my application, so that I can use it with ajax calls.
Here is what I have in my application.ini
;Routes
resources.router.routes.products.route = "/backend/api/:command"
resources.router.routes.products.defaults.module = "backend"
resources.router.routes.products.defaults.controller = "api"
resources.router.routes.products.defaults.action = "index"
When a ajax call is made, to /backend/api/SomeCommand, the following error is produced:
Message: Invalid controller specified (backend)
array (
'controller' => 'backend',
'action' => 'maestro',
'module' => 'default',
)
as you can see module has been set to "default", instead of "backend", and controller is "backend" instead of "api", what could have caused this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您在这个与请求匹配的路由之后定义了另一个更通用的路由。
您需要按照从最不具体到最具体的顺序定义路由,通常通过使用
backend/api
前缀等固定术语来提高具体性。请参阅基本重写路由器操作,特别是
仅供参考:您不需要在路由前面加上正斜杠
Looks like you've got another more generic route defined after this one that's matching the request.
You need to define your routes in order of least to most specific, specificity usually being improved by the presence of fixed terms like your
backend/api
prefix.See Basic Rewrite Router Operation, in particular
FYI: You don't need to prefix your routes with a forward-slash