如何在micro phalcon应用中设置服务di的DI?当设置DI与服务不起作用时,如何处理该应用程序?

时间:2016-10-17 12:56:39

标签: php phalcon

如何在micro phalcon应用中设置服务di的DI?当设置DI与服务不起作用时,如何处理该应用程序?

    use Phalcon\Mvc\Micro;
    use Phalcon\DI\FactoryDefault; 
    use Commonapi\App\Library\ApiServices as ApiServices;
    class Bootstrap
    {
     public function run($opt){
     $app = new Micro();
     foreach ($loaders as $service) {
         $function = 'init' . ucfirst($service);
         $this->{$function}($app);
     }
     $services = new ApiServices($this->di);
     $app->setDI($services->di);
     return $app->handle();
 }

//have loaded config,routes,loader by separate functions

1 个答案:

答案 0 :(得分:-1)

为什么要将$app完全传递给$function?什么不起作用?有什么错误吗?也许做类似的事情:

foreach ($loaders as $service) {
    $function = 'init' . ucfirst($service);
    $this->{$function}();
}
$services = new ApiServices($this->di);
$app = new Micro($services->di);
return $app->handle();

究竟是什么ApiServices