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

DI -> get not work

I have some code like this:

    $di = new \Phalcon\DI\FactoryDefault();
    $di->set('url', function () use ($config) {
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri($config->application->baseUri);
        return $url;
    });

So i want to get url with $di->get('url'), but it doesn't work. The HTTP500 error appeard. I think it is an error about phpframework.

Can anybody help me ? Thanks very much

Evan Can you check your error log and send us the output please.

Also you are using the FactoryDefault, FactoryDefault has already the url service registered : https://docs.phalcon.io/en/latest/reference/di.html#factory-default-di

Moreover, is it the first time you install phalcon on your computer ? How did you install it ?

The code works for me with the latest 1.3.0

error_reporting(E_ALL);
ini_set('display_errors', 1);

could help.