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 config parameters in Phalcon Version 2.0.0 and Phalcon Version 3.4.0

Production Server Phalcon Version 2.0.0
Testing Server Phalcon Version 3.4.0

index.php on both systems:

$config = new Phalcon\Config\Adapter\Ini('../app/config/config.ini');
$di->set('config', $config, true);

Accessing the config parameters in Phalcon Version 2.0.0 Model

$this->config->session->parameter;

Accessing the config parameters in Phalcon Version 3.4.0 Model

Phalcon\DI::getDefault()->get('config');

In the Model the 2.0.0 way of accessing the config parameters dosent work annymore.
These is a big Issue for us because we do not want to change all the config paths in our Models.

To have the same access of the config parameters trouth the whole application makes absolut sense.
I dont think it make sense to use it differently in models views or controllers.

Is there an way to configure Phalcon Version 3.4.0 to use the config parameters in Models as the same as in Phalcon Version 2.0.0 ?

edited Jul '18

If i understand correcly, you are trying to access the DI $config from a model instance?

It was removed because having an InjectionAware Model could interfere with property column names.

If you have a base model class, add this there:

class BaseModel extends \Phalcon\Model
{
   /** @var \Phalcon\Config */
    protected $config;
    public function initialize()
    {
        $this->config = $this->getDI()->get('config');
    }
}

Or, as an alternative, implement a magic getter:

/**
 * @property \Phalcon\Config $config
 */
class BaseModel extends \Phalcon\Model
{
    public function __get($name) {
        if($name === 'config') {
            return $this->getDI()->get('config');
        }
        return parent::__get($name);
    }
}


404
edited Jul '18

https://olddocs.phalcon.io/en/3.0.3/api/Phalcon_Mvc_Model_Manager.html

Would it be possible to initialize the DI $config for Phalcon Models with the Phalcon MVC Model Manager ?