I’m using DI-PHP as the container.
I have a controller class named “Users” and I’m trying to pass the “UserModel” to it’s constructor.
services.php
$container->set('Database', function() use ($config){
return new PDO(...);
});
$container->set('Users', function(ContainerInterface $c){
return new \Controller\Users(
$c->get('UserModel') // this is line 23
);
});
$container->set('UserModel', function(ContainerInterface $c){
return new \Models\UserModel($c->get('Database'));
});
Basically when I remove $c->get('UserModel')
from the Users container, everything works. I think I might be misunderstanding how DI works, but this is the error:
- file: “…Core\services.php”
- line: 23
- message: “Class ‘Models\Planner’ not found”
- type: “Error”