I use constructor injection in my Controller:
protected $_usersRepository;
public function onConstruct(UsersRepository $repository)
{
$this->_usersRepository = $repository;
}
public function indexAction()
{
$this->_usersRepository->create();
}
and register DI user repository
$di->set('userRepository', [
'className' => 'Hyenas\Repositories\UsersRepository'
]);
$di->set('indexController', [
'className' => 'Hyenas\Backend\Controllers\IndexController',
'arguments' => [
['type' => 'service', 'name' => 'userRepository'],
]
]);
but i has error Catchable fatal error: Argument 1 passed to Hyenas\Backend\Controllers\IndexController::onConstruct() must be an instance of Hyenas\Repositories\UsersRepository, none given in /vagrant/first-app/apps/modules/backend/controllers/IndexController.php on line 11
I use document here https://docs.phalcon.io/en/latest/reference/di.html#constructor-injection how can i solve that's, I'm newbie working phalcon, please help me thank you.