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

Annotations router

I'm trying to use annotations router but I'm facing the below exception

"A dependency injection container is required to access the 'annotations' service"

You can review my settings and configurations below

Setting up annotations router in public/index.php

<?php
$di->set('router', function () {
        $router = new \Phalcon\Mvc\Router\Annotations(false);
        $router->addResource('User');
        return $router;
    });

My UserController.php

<?php
/**
 * @RoutePrefix("/user")
 */
class UserController extends \Phalcon\Mvc\Controller
{
    /**
     * @Get("/signin")
     */
    public function signinAction()
    {
    }
} 

When point my browser to domain/user/signin I face the mentioned exception. I would appreciate any kind of help as I'm new to the world of Phalcon.



1.4k
Accepted
answer

I found the answer! Adding the following invocation fixed my problem.

$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);