We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

A dependency injection container is required to access the 'request' service

Error message A dependency injection container is required to access the 'annotations' service and A dependency injection container is required to access the 'request' service

<?php

$router = new Phalcon\Mvc\Router(false); //$router = new RouterAnnotations(false);

$router->add("/api", array( "controller" => "index", "action" => "index" ));

// $router->addGet("/api/:controller/:action/:params" , array( // array( // "controller" => 1, // "action" => 2, // "params" => 3, // ) // ));

$router->add("/api/:controller" , array( array( "controller" => 1, "action" => "index",

)

))->via("GET");

$router->add("/api/:controller" , array( array( "controller" => 1, "action" => "index",

)

))->via("POST");

$router->add("/api/:controller/:params", array( array( "controller" => 1, "action" => "view", "params" => 3 ) ))->via("GET");

$router->add("/api/:controller/:params", array( array( "controller" => 1, "action" => "view", "params" => 3,

)

))->via("PUT");

$router->add("/api/:controller/:params", array( array( "controller" => 1, "action" => "view", "params" => 3,

)

))->via("DELETE");



2.6k

A dependency injection container is required to access the 'request' service

Has anyone encounter this problem



51.2k

You try to use new Phalcon\Mvc\Router as a stand-alone component ?



2.6k
edited May '15

what do you mean stand alone?

i use this

use Phalcon\Mvc\Router

$router = new Router(false);

On Wed, May 20, 2015 at 7:49 PM, Calin Rada [email protected] wrote:



51.2k
Accepted
answer

I mean, you can use any component from Phalcon, independent. You can use only the ORM, you can use only it's DI, etc. Try this:

$di     = new \Phalcon\DI\FactoryDefault();

$router = new Phalcon\Mvc\Router(false); 
$router->setDI($di);
$router->add("/api", array( "controller" => "index", "action" => "index" ));


2.6k

OW wow thanks I'll try that