We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to get the config params in Model?

return new \Phalcon\Config(array(
    'database' => array(
        'adapter'  => 'Mysql',
        'host'     => '',
        'username' => 'root',
        'password' => 'root',
        'dbname'   => 'taobao',
        'prefix'   => 'sh_',
$di->set('db', function () use ($config) {
    return new DbAdapter(array(
        'host' => $config->database->host,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname' => $config->database->dbname,
        'prefix' => $config->database->prefix

How can I get the 'prefix' params in Model ?


Do you mean the one that is store in app/config/config.php ? If so, you can register config array as a service and then can acces to its properties eveywhere in your app:

// in services.php:
$di->set('config', function() use ($config) {
return $config;
}, true);

// elsewhere in your app:


Try this


//in services.php
$di->set('config', function () use ($config) {
    return $config;
}, true);

//in controller

//in model

Thank your!!! Both need!!!

In services: Phalcon 3.0.1

$di->set('myservice', function () {
    $config = $this->getConfig();
}, true);