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

Instantiate a class in app/libraries and pass the database connection to the instance

Hello,

I am a Phalcon 3.3.1 newbie.

I have not found any docs relating to instantiate a class in app/libraries and passing the database connection to the instance.

How can I instantiate a class in app/libraries and pass the database connection to the instance?



85.5k

after you register db connection as a service , from the tutorials


//controller
$this->getDI()->get("DB");

//static
$db = \Phalcon\Di::getDefault()->get("DB")