calinrada / PhalconUserPlugin

185 stars 68 forks source link

Fix for "Service 'config' wasn't found" error #24

Closed mizterp closed 9 years ago

mizterp commented 9 years ago

I was getting the following error:

Service 'config' wasn't found in the dependency injection container

To fix this I had to do add the following in the Services.php (where Services are globally registered):

//added this "set"
$di->set(
    'config',
    function () use ($config) {
        return $config;
    }
);

//Based on documentation, I only had this
$di['dispatcher'] = function() use ($di) {
    $eventsManager = $di->getShared('eventsManager');
    $security = new \Phalcon\UserPlugin\Plugin\Security($di);
    $eventsManager->attach('dispatch', $security);

    $dispatcher = new Dispatcher();
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
};
calinrada commented 9 years ago

If you use it independently, then yes, you need to register the config service. Normally, if you use it within an app, you should already have the config service registered.