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.

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);