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

Quick Config Question

I have a config DI that is setting a date format

I want, in a Model, to do a showDate() function using the $this->config->dateFormat however DI items do not seem to appear within Models.

How would the Phalcon community best implement a global format like that? I can't do afterFetch format this way right now.



22.6k
Accepted
answer

Just noticed another discussion stating something like this

$this->getDi()->get('config')->app->timeformat

works.

Thanks

If you gonna access it/config many times then you can do something like:

abstract class AbstractModel extends \Phalcon\Mvc\Model
{
    protected $_config; // or even $_timeFormat

    public function onConstruct()
    {
        $this->_config = $this->getDi()->get('config');
    }
}
edited Jun '16

Thank you for the response Wojciech. I actually put that in because it cleans up my ongoing development !! :)