drxm72811 2014-05-03 01:24
浏览 32

PHP挂钩设置通过不同的类调用

I'm going to structure this as best I can. Basically I have a Hook class that works by adding supplied hooks.

An example of this would be:

$this->registry->hook->add('HOOK_NAME', 'CLASS_NAME||METHOD_NAME')

The hook adding, calling, removing functions work great, now the issue resides when I set the hook in a separate method in a completely different class.

An example of this would be when a user logs in.

The path they take is User Controller -> Form Class -> Login Process Function

Now within this login process function, I'd like to set a hook to be called later to end the session. (Would be added as stated above)

The issue seems to be that it gets set but doesn't stay persistently, if that makes sense?

If anyone is interested, this is what the hook add function looks like:

function add($hook, $callback, $params = '') {
        //make sure the hook is defined
        if (!isset($this->hooks[$hook])) {
            $this->hooks[$hook] = array();
        }
        //add the callback to the hook
        $this->hooks[$hook]['callback'] = $callback;
        // add the params if supplied
        if (!empty($params)) {
            $this->hooks[$hook]['params'] = $params;
        }
    }

Should I be using magic methods __set() and __get() ?

Any help would be appreciated! :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?