owsx 发表于 2012-9-28 15:23:18

ci中的hook用于什么方面

最近把ci的代码看了一遍。对hook这个类作用不是很理解。求高手解释。

大道达人 发表于 2012-9-28 22:07:19

hook是神器,具体怎么用,要看实现什么功能

power721 发表于 2012-9-29 09:18:59

就是在系统引导流程中插入自己的代码,而不用修改核心代码。

owsx 发表于 2012-9-29 10:22:43

貌似可以在 控制器之前(或者其他时候) 执行自己的代码,执行某个对象的方法或者某个函数。
我现在把需要在所有控制器中都执行的代码移到hook中了。
应该就是这么用的吧?

hyungook 发表于 2012-12-23 03:17:09

power721 发表于 2012-9-29 09:18 static/image/common/back.gif
就是在系统引导流程中插入自己的代码,而不用修改核心代码。

{:2_36:}精髓。

qingxin 发表于 2012-12-25 17:29:23

虽然很神,但是实际上运用hook的情况不多(因为ci已经解决了大部分你可能会遇到的问题)。当使用扩展无法达到目的时,才会考虑钩子

hyddd 发表于 2013-1-17 10:58:29

跟其java、net,这种hook功能还是太弱,使用起来不方便。
最近在纠结,扩展任务完成后自动化邮件,又不想入侵原业务代码,其实本身就不应该入侵,但实现起来各种纠结。

niudongwei 发表于 2013-2-7 03:39:37

试试drupal 框架就能深刻体会hook的意义了 :)

Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

smartweb 发表于 2013-2-7 07:32:17

听起来好神奇,想用一下,我也不知道怎样用;P

xiaozhuaisnow 发表于 2013-3-15 17:52:53

hook在你执行controller之前执行,举一个例子吧,有一次,项目要上线,但是服务器时间怎么调也不正确。(因为要存订单时间),没办法,一时调不好服务器,就写了一个钩子设置时区。(只是作为临时方案)
页: [1]
查看完整版本: ci中的hook用于什么方面