开发者

Is there a Rails like "before" in PHP Zend Framework

In Rails, we can execute 开发者_开发知识库functions, before a URL is called, for example. IS there a something similar in zend framework?

For example, if I want to update the datetime of the last viewed page, at every page for the currently logged in user, I'd want to call a function everytime a URL is called. How do I do this?


You would create a front controller plugin that would execute your short function on every request. If you only want to do it for logged in users, then you would add this plugin later in the stack, so that it executes after your login logic.

You would then get the logged in user using $auth = Zend_Auth::getInstance() and $auth->getIdentity().

You should look here for how to create a Front Controller Plugin and read about how to use them.

The best article on Plugins - http://devzone.zend.com/article/3372

The documentation - http://framework.zend.com/manual/en/zend.controller.plugins.html

The "hook" points at our disposal are:

>     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

I won't tell you which to use, as you should know this the best from knowing how your application works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜