Zend Framework - 路由:通过参数调用操作
$router->addRoute('routeName', new Zend_Controller_Router_Route(
'test/:category/', array(
'module' => 'default',
'controller' => 'test',
'action' => ':category'
)
));
这是我目前的代码(见上文)。我现在如何通过给定参数(通过 URL)调用该操作? url 看起来像这样: domain.com/test/news/
现在我想在测试控制器中调用动作 newsAction() 。使用上面的代码,我收到错误:操作“类别”不存在并且未陷入 __call()
$router->addRoute('routeName', new Zend_Controller_Router_Route(
'test/:category/', array(
'module' => 'default',
'controller' => 'test',
'action' => ':category'
)
));
That's my code at the moment (see above). How could I call now the action by a given param (via URL)? The url look e.g. like that: domain.com/test/news/
and now I want to call the action newsAction() in the test controller. With the code above I get the error: Action "category" does not exist and was not trapped in __call()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的发言毫无用处。您想要实现的目标正是标准路线的运作方式。
Your statement is useless. The goal you want to achieve is exactly how the standard route works.
您应该能够在路线中简单地使用 :action 。或者,您可以在控制器中使用自定义 __call() 方法来捕获动态操作名称。
You should be able to simply use :action in your route. Alternatively, you could use a custom __call() method in your controller to catch dynamic action names.