在PHP Zend Framework中是否存在类似“之前”的Rails

时间:2011-08-31 13:59:15

标签: php zend-framework

在Rails中,我们可以在调用URL之前执行函数。在zend框架中有类似的东西吗?

例如,如果我想更新上次查看页面的日期时间,在当前登录用户的每个页面上,我都想在每次调用URL时调用一个函数。我该怎么做?

1 个答案:

答案 0 :(得分:4)

您将创建一个前端控制器插件,可以在每个请求上执行您的短函数。如果您只想为登录用户执行此操作,那么您稍后会在堆栈中添加此插件,以便在登录逻辑之后执行。

然后,您将使用$auth = Zend_Auth::getInstance()$auth->getIdentity()来获取登录用户。

您应该在这里查看如何创建Front Controller插件并阅读有关如何使用它们的信息。

关于插件的最佳文章 - http://devzone.zend.com/article/3372

文档 - http://framework.zend.com/manual/en/zend.controller.plugins.html

我们可以使用的“钩子”点是:

>     routeStartup(): prior to routing the request
>     routeShutdown(): after routing the request
>     dispatchLoopStartup(): prior to entering the dispatch loop
>     preDispatch(): prior to dispatching an individual action
>     postDispatch(): after dispatching an individual action
>     dispatchLoopShutdown(): after completing the dispatch loop

我不会告诉你使用哪个,因为你应该知道你的应用程序是如何运作的。