I'm creating a RESTful API in Phalcon PHP, I set the DI and the database information as always using:
This is how I'm configuring the database in the DI.
use Phalcon\Db\Adapter\Pdo\Postgresql as DbAdapter;
$di = new FactoryDefault();
$di['db'] = function() use ($config) {
return new DbAdapter(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"schema" => $config->database->schema,
));
};
Then setting the DI
$app->setDi($di);
And I'm handling the actions like this:
//Gets a client information
$app->get('/client', array(new ClientController, 'getAction'));
The problem is that when ClientController creates a new model object it simply returns an error saying that the table was not found and I think is because it is not loading the database information from the DI, so my question is, how can I set up that information globally, is it not supposed that Phalcon do it?
The database works fine in the main application controller, but I want to order the methods in other different subcontrollers and there is where the database config doesn't work.
I'm doing this as stated in the documentation:
https://docs.phalcon.io/es/latest/reference/micro.html
Thanks.