Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

unknow exception phalcon

Hi, i am tried develop a system in phalcon, but when a session in PHP expire a receive a following exception:

Fatal error: Uncaught exception 'Phalcon\Mvc\Model\Exception' with message 'A dependency injector container is required to obtain the services related to the ORM' in phalcon/mvc/model.zep:215 Stack trace: #0 [internal function]: Phalcon\Mvc\Model->getModelsMetaData() #1 [internal function]: Phalcon\Mvc\Model->toArray() #2 [internal function]: Phalcon\Mvc\Model->serialize() #3 {main} thrown in phalcon/mvc/model.zep on line 215

I tried debug my code, but without success, anyone know what is it?

Thank so much

Show us your di declartion.


My DI declaration:

$di = new FactoryDefault();

$di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; });

$di->set('url', function () use ($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri);

return $url;

}, true);

$di->set('config', $config, true);

$di->setShared('view', function () use ($config) {

$view = new View();


    '.volt' => function ($view, $di) use ($config) {

        $volt = new VoltEngine($view, $di);

            'compiledPath' => $config->application->cacheDir,
            'compiledSeparator' => '_'

        return $volt;
    '.phtml' => 'Phalcon\Mvc\View\Engine\Php'

return $view;


$di->set('db', function () use ($config) { return new DbAdapter($config->database->toArray()); });

$di->set('modelsMetadata', function () { return new MetaDataAdapter(); });

$di->set('security', function () {

$security = new Security();
return $security;

}, true);

$di->set('message', function () { $flash = new Flash([ 'error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', ]);

return $flash;


$di->set('dispatcher', function () {

$event = new EventsManager();
$event->attach("dispatch:beforeExecuteRoute", new Controle);
$event->attach('dispatch:beforeException', new Controle);
$event->attach('dispatch:beforeNotFoundAction', new Controle);

$dispatcher = new Dispatcher();
return $dispatcher;


$di->set('log', function() use ($config){ return new Log($config->application->logDir); }, true);

$di->set('param', function() use ($config){ return new Parametros(); }, true);

$di->set('mail', function() use ($config){ return new Mail(); }, true);

edited Nov '15

Check the documentation how to declarate Metadata provider, you can use files/apc/xcaxhe/session/memory.

Oh sry, acutally MetaDataAdapter is just alias in your code. What is it ?


Thanks for response Jurigag!! The MetaDataAdapter is a alias for Phalcon\Mvc\Model\Metadata\Memory; My problem start when i store a model objet in session and after the 15 minutes i refresh the page and receive the error, i think that is because of the Metadata\Memory!! I change the namespace of Metadata for Phalcon\Mvc\Model\Metadata\Apc and i put the life time better and resolved the problem for me! Thanks

Yea no problem, just remember now if you will change something like adding new field in database and property in model you will need to reload php to refresh apc. You can just uncomment those lines or check is this dev enviroment and just dont add this modelsMetadata to di(its not necessary)