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

How can I access config in a libary?

I have a library of my own and I would need to access Phalcon\Config. I just can't figure out how I can reach it. How can I access config in a library?

edited Feb '16

Damn my idea was working all the time I just had another error. I can reach it like this. Is this the way I am supposed to do it?

$config = \Phalcon\Di::getDefault()->getShared('config');

edited Feb '16

Yes, this is the correct way.

Another example in model:

// or 

One more example i found in Helper class of mine:

 $di = \Phalcon\DI::getDefault();
 $url = $di['url']->get(.....);
edited Feb '16

How are you registering your config?

How are you registering your librarys?

Really a lot of this question depends on your bootstrapping method with phalcon.

My advice components. https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_User_Component.html#methods

Registeer your namespaces

$loader = new \Phalcon\Loader();
    'Name\Library' => $config->application->libraryDir
namespace Name\Library\YourClass;
use Phalcon\Mvc\User\Component;

class YourClass extends Component

    // assuming you ahve registered your config file in DI() shown below. 
$di->set('config', $config);

there are serveral missing parts to this that i assuem you arleady have in place given the nature of your question.