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.

Strange error with the phalcon router

I'm developing a website using the PHP Phalcon Framework and I am really stuck in a problem with the router, here I go.

In order to restrict the HTTP Method for your route to match, I use this declaration:

$router->addGet('/admin/paginas', array(
    'namespace' => 'Backend\Controllers',
    'controller' => 'pagina',
    'action' => 'list'
));

But it fails with the following error:

Unexpected value type: expected object implementing Phalcon\DiInterface, null given I have some other routes defined in the same services.php file with add and there's no problem with them, for example:

$router->add('/oportunidades-trabajo', array(
    'controller'    => 'page',
    'action'        => 'oportunidadesTrabajo'
));

Works perfectly fine. I've tried removing namespace, changing the controller, using short sintax, using ->via() instead of addGet, but nothing solves my issue.

If i remove this route declaration everything works fine.

Here's the full declaration of the router:

$di->set('router', function () {
$router = new Router(false);

$router->removeExtraSlashes(true);

# FRONT END

$router->add('/oportunidades-trabajo', array(
    'controller'    => 'page',
    'action'        => 'oportunidadesTrabajo'
));

# BACK END - Paginas

# list
$router->addGet('/admin/paginas', array(
    'namespace' => 'Backend\Controllers',
    'controller' => 'pagina',
    'action' => 'list'
));

# NOT FOUND
$router->notFound(array(
    'controller'    => 'page',
    'action'        => 'page404'
));

$router->handle();
return $router;
});

I would appreciate a lot your help, as I'm stuck with this and I cannot continue with the project.

Thanks a lot in advance for your time.



83.4k
Accepted
answer

$router->handle(); must not be called in the service definition, it's called by Phalcon\Mvc\Application

Thanks a lot, that actually solved the problem! ;)

Adrià,