Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Database connection problem in Models using Micro

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


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:



Please let us see how you have registred your db service in the DI

I updated the information in the first post, hope you understand.


edited Oct '14

db config looks okay, also you said that db access is working fine with another controller (<=> your config file is correct) , so maybe in your ClientController -> getAction you call a specific model (saying ClientModel wich is different from the one you call in MainController). Perhaps setting the source in your ClientModel will help (because phalcon complains that it is not finding the table):

public function getSource()
        return "the_robots";


I discovered that is getting the DI and the problem now is that the Database adapter is not using the schema I set up when creating the adapter, I opened another discussion here, also I'm having this problem frequently with PostgreSQL.