We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to use Phalcon Micro as a service?

I need to use \Phalcon\Mvc\Micro as a service.

$di = new FactoryDefault();

$di->set('app', function () use ($di) {
    $app = new Micro($di);
    return $app;
});

$app->handle();

i did apply the above mention approach but it did not get do what i wanted. Please give me a direction.

And what is exactly your problem? Just access $di->app

Also why you want to do it?

edited Mar '17

I wanted to use the instance of Micro from anywhere in my project. I have found a way to use that. $app = new Micro(); $app->setDI($di); thank you



145.0k
Accepted
answer
$app = new Micro(); $app->setDI($di); 

Exactly, this is correct way to do this :)