Zend Framework _forward 到同一控制器内的其他操作
我如何转发到同一控制器内的其他操作,以避免重复所有调度过程?
例子: 如果我指向用户控制器,默认操作是该函数内的indexAction(),我使用_forwad('list') ...但是所有调度过程都会重复..我不知道
什么是正确的方法?
How can i forward to other action inside the same controller avoiding repeat all dispatch proccess ?
Example:
If i point to User Controller the default action is indexAction() inside this funciton i use _forwad('list') ... but all dispatch proccess are repeated.. and i dont that
Whats is the right way ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常,您将安装路由来将用户重定向到正确的(默认)操作,而不是索引操作(阅读如何使用 Zend_Router 从给定路由重定向)。但是,如果您确实愿意,您可以直接从控制器手动执行所有操作(但这称为“编写黑客代码以实现肮脏的目标”)。
更改要渲染的“视图脚本”,然后调用您的操作方法......
如果您倾向于经常使用此“技巧”,也许您可以编写一个在应用程序中扩展的基本控制器,它可以简单地有一个方法like :
然后从您的操作中调用该方法...
注意 :这不是官方的方法,但它是一个解决方案。
Usually, you will install routes to redirect your users to the proper (default) action, instead of the index action (read how to redirect from a given route using Zend_Router). But you can do everything manually if you really want to (however this is called "writing hacker code to achieve something dirty") directly from the controller.
Change your "view script" to be rendered, then call your action method....
If you tend on using this "trick" often, perhaps you may write a base controller that you extend in your application, which can simply have a method like :
Then call the method from your action...
NOTE : this is not the official way to do it, but it is a solution.
我们还可以使用这个 Helper 来重定向
We Can Also use this Helper To redirect
如果您不想重新分派,则没有理由不能简单地调用该操作 - 它只是一个函数。
If you don't want to re-dispatch there is no reason you can't simply call the action - it's just a function.
您还可以创建一条路线。例如,我在 /application/config/routes.ini 中有一个部分:
现在您只需要一个操作,即索引操作,但请求 rss/feed 也在那里。
You could also create a route. For example I have in my /application/config/routes.ini a section:
Now you only need one action and that is index action but the requess rss/feed also goes there.