douliao5942 2013-09-29 19:46
浏览 71
已采纳

Phalcon \ MVC \ Models中的自定义事件管理器会抛出错误

I am trying to use Events Manager example as described at http://docs.phalconphp.com/en/latest/reference/models.html#using-a-custom-events-manager.

class Products extends Phalcon\Mvc\Model
{
    public function initialize()
    {
        $eventsManager = new Phalcon\Events\Manager();

        $eventsManager->attach('model', function($event, $robot) {
            // Do something (or nothing at all).
            return true;
        });
        $this->setEventsManager($eventsManager);

    $this->setSource('products');
    }
}

$o = Products::findFirst();
$o->we = 5;
$o->save();

This results in the following error:

Script raised E_ERROR with message "Phalcon\Mvc\Model\Manager::notifyEvent(): Call to method fire() on a non-object"

What am I missing in EventsManager setup?

I am on Phalcon 1.3.0.

Thanks, Temuri

  • 写回答

1条回答 默认 最新

  • duanhuai7532 2013-09-30 02:08
    关注

    This looks like a bug:

        if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { 
    +       zval *mgr;
    
            PHALCON_INIT_NVAR(entity_name);
            phalcon_get_class(entity_name, model, 1 TSRMLS_CC);
    -       if (phalcon_array_isset(custom_events_manager, entity_name)) {
    +       if (phalcon_array_isset_fetch(&mgr, custom_events_manager, entity_name)) {
    
                PHALCON_INIT_NVAR(fire_event_name);
                PHALCON_CONCAT_SV(fire_event_name, "model:", event_name);
    
                PHALCON_INIT_NVAR(status);
    -           phalcon_call_method_p2(status, custom_events_manager, "fire", fire_event_name, model);
    +           phalcon_call_method_p2(status, mgr, "fire", fire_event_name, model);
                if (PHALCON_IS_FALSE(status)) {
                    RETURN_CTOR(status);
                }
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?