duanjing4667 2011-08-31 13:59
浏览 12

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

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?

  • 写回答

1条回答 默认 最新

  • dongxian3852 2011-08-31 14:03
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)