Hello.
Can’t figure out, what am I doing wrong. I want to make rest API with versioning (using advanced template). Here is my directory hierarchy:
api
config
main.php
...
modules
v1
controllers
TestController.php
runtime
...
web
index.php
...
backend
...
common
...
frontend
...
That’s what I have in config (main.php):
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-api',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'api\controllers', // I also tried to set 'api\modules\v1\controllers' here
'bootstrap' => ['log'],
'modules' => [
'v1' => [
'basePath' => '@api/modules/v1',
],
],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'user' => [
'identityClass' => 'common\models\User',
],
...
],
'params' => $params,
];
And this is controller code:
<?php
namespace api\modules\v1\controllers;
use yii\rest\Controller;
class TestController extends Controller
{
public function actionIndex()
{
return 'ok';
}
}
When I’m trying to get http://host/v1/test/index I’m getting #404. Before I decide to use modules for versioning everything was fine: http://host/test/index was showing results of action (controller was in api/controllers/TestController.php).
Please, help me to find my mistake.