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

Is it possible to access config within a migration?

Hi, I would like to be able to use some shared variables in all my migrations. Usually that's what the config is for in the application, right? However I have not been able to use an instance of DI/config in my migrations.

I have config injected into DI, and so I have DI components in Controllers available simply as $this->config->... In models I feel like I need to get an instance of Di out first, like so DI::getDefault()->getShared('config')->... not sure if there is a "cleaner" way of doing this. Feel like those things should be available easier in Models too. In migrations though none of the above seem to be working. I also tried a new instance of Config. Basically, nothing I have tried worked. How do I get to use some shared variables inside migrations? I suppose I could just include a file or something, but that would seem to be so un-framework-ly. I tried googling too. Always do. Finally, this is my first postr in here. Obviously I am a newbie.

Thanks.



22.6k
Accepted
answer

If you have loaded the config into the DI then yes...


        //Retrieve Current DI
        $di = \Phalcon\DI::getDefault();
        $prefix = $di->getConfig()->database->prefix;