dpcnm2132 2016-02-01 06:00
浏览 120
已采纳

phalcon中的DI和$ app错误

I use micro app Phalcon, I created a DI to my class named utility. When I get the shared utility through $app->utility an error occurred.

$di->setShared('utility',function(){
    return new utility();
});
$app->get("213",function(){});
$app->utility;

error: Access to undefined property utility in ($app)

But if I change the code to

$di->setShared('utility',function(){
    return new utility();
});
$app->utility;
$app->get("213",function(){});

It works fine. WHY?

PHP = 5.6.17

Phalcon = 2.7 or 2.8 or 2.9

windows 10 + nginx

THANKS!

  • 写回答

1条回答 默认 最新

  • douzhong1907 2016-02-04 09:23
    关注

    $app is an instance of Macro. $app = Macro($di); post $di as a param to Macro and it's work fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?