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

eventsManager not AUTO Injected into a component ?

I declare a subclass of Phalcon\Mvc\User\Component but the getEventsManager return null? is the eventsManager not auto injected? or I must inject it by myself? @phalcon



6.9k
Accepted
answer

You're right, you need to inject it yourself.

\Phalcon\Mvc\User\Component implements both \Phalcon\Di\InjectionAwareInterface and \Phalcon\Events\EventsAwareInterface. The first provides you with setDI($di) and the second with setEventsManager(\Phalcon\Events\ManagerInterface $eventsManager), so you can set them and use them accordingly, but no they're not provided by default.