Not 100% clear on the Slim framework structure or if there are built in methods to handle such a task in Slim, but would it not be best to pass it this way?
$foo = new FooClass($db);
And then in the FooClass()
just have a call to set the $db
in constructor? Something like this?
class FooClass {
private $db = null;
function __construct($db) {
$this->db = $db;
}
}
Again my POV is coming from generic PHP class & OOP knowledge. So unclear if there is a better way in Slim. If there is, would be welcome to understand more.