简体   繁体   中英

Phalcon router addGet error

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.

$router->handle(); must not be called in the service definition.

Just delete $router->handle();

Source: http://forum.phalconphp.com/discussion/3623/strange-error-with-the-phalcon-router

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM