Yii2 App Basic REST - Error 404 when controller has different namespace

Hi all,

If I let my API controller at the same level from web controllers, the API routes work, but if I move my API controller inside a directory, we say, api, and I change its namespace, then Yii2 isn’t able to find the routes.

To be more clear, I respect the structure for the basic app:

  • assets
  • commands
  • components
  • config
  • controllers

    Inside controllers, I have some controllers, but I want to have, for instance, some API controllers inside a directory called api inside the controllers directory:
  • controllers
    • api

And changing its namcespace to app\controllers\api and setting in the urlManager:

[
                    'class' => 'yii\rest\UrlRule',
                    'controller' => '**api**\mycontroller',
                    'pluralize' => false,
                    ...
 ],

Doesn’t work.

How do I do to achieve it?