0

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Are you setting your $di variable somewhere in your bootstrapping process? The error seems to indicate that it's looking for $di, but finding null. – Peter Oct 06 '14 at 11:03

1 Answers1

1

$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

Thang Nguyen
  • 1,161
  • 4
  • 16
  • 30