Hi guys, I'm trying to setup a micro apllication with controllers. I initialized a DI and set 'db' :
$di = new FactoryDefault();
$di->set('db', function () use ($di) {
$config = $di->getShared('config');
$connection = new DbAdapter(array(
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname
));
return $connection;
});
and set some collections for routing:
foreach($this->config->api->controller AS $controller => $routes) {
$collection = new Collection();
$controller = 'Kaasahealth\\Api\\' . $controller;
$collection->setHandler($controller, true);
foreach($routes AS $method => $route) {
$collection->get($route, $method);
$collection->post($route, $method);
}
$app->mount($collection);
}
$this->config was loaded before :) than I try to start my app...
$app = new \Phalcon\Mvc\Micro();
$app->setDI($di);
$app->handle($route);
On handle he calls the controller as expected but when I try to get data from my Model I get
"Service 'db' wasn't found in the dependency injection container"
.... How can I set the db Service?
Tanks for helping me :)