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.

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");



1.1k

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

Has anyone encounter this problem



34.0k

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



1.1k
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:



34.0k
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" ));


1.1k

OW wow thanks I'll try that