We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Access to the configuration when adding a Mysql connection in the FactoryDefault

Hi,

I have an ini file:

[database]
host      = localhost
username  = test
password  = ****
dbname    = test

In index.php i have:

use Phalcon\Config\Adapter\Ini as IniConfig;
$di = new FactoryDefault();
$di->set('config', function () {
return new IniConfig("config/config.ini");
});
// Set up the database service
$di->set('db', function () {
return new PdoMysql(
    array(
        "host"     => $this->config->database->host, // or $di->config->database->host,
        "username" => $this->config->database->userName,
        "password" => $this->config->database->password,
        "dbname"   => $this->config->database->dbName
    )
);
});

When I try to open the connexion it doesnt work, i have an error on all " $this->config->database->....":

<b>Notice</b>:  Undefined property: Phalcon\Di\FactoryDefault::$config

Can you help me?