dou91808 2014-01-19 11:14
浏览 5
已采纳

PHP - 什么是事件管理器? [关闭]

I have seen in a number of PHP frameworks the use of "event manager" classes. What exactly is an event manager within the scope of a "normal" MVC framework and what does it offer to the application in general?

  • 写回答

3条回答 默认 最新

  • drz73366 2014-01-19 13:05
    关注

    First have a read about event driven programming to understand the basic idea.

    I think every of the frameworks you've tagged has a manual page about the event system as well. At least CakePHP has a pretty detailed one about it's event system and it's event manager. The description of it is already half of an explanation what an event manager is:

    The event manager is responsible for keeping track of event listeners, passing the correct data to them, and firing them in the correct order, when associated events are triggered. You can create multiple instances of this object to manage local events or keep a single instance and pass it around to manage all events in your app.

    An event manager can attach listeners, or receivers, objects that listens or are "connected" to events. When an event is fired and dispatched by the event manager all listeners that are registered to one or more events will receive the event object instance and can work with it.

    Be careful with events, correctly used they're great, inappropriate used they can make your application a hard to debug and hard to understand mess. Don't use them just because they're cool, document the events in your application.

    Here is an example of how to inject additional fields into a form using the CakePHP event system. This use case might suit a CMS or if you have to conditionally add something to a form through a plugin system.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 VUE项目怎么运行,系统打不开