REST API: Object not found


(tyhja-mitaton) #1

I’m trying to use restful api but it always throws error “object not found”
Seem to be something wrong with routing, can’t grasp what though…
The catalog structure as the following:
-api
–confing
–web
–modules
—v1
----controllers
----models
—Module.php

api/config/main-local.php:
url manager, module
    '    urlManager' => [
                'enablePrettyUrl' => true,
                'enableStrictParsing' => true,
                'showScriptName' => false,
                'rules' => [
                    [
                        'class' => \yii\rest\UrlRule::class,
                        'controller' => ['v1/user'],
                        'prefix' => 'api',
                        'extraPatterns' => [
                            'GET /' => 'test',
                        ],
                    ],
                ],
            ], 

'modules' => [
    'v1' => [
        'basePath' => '@app/modules/v1',
        'class' => api\modules\v1\Module::class,
    ]
],

module class:
namespace api\modules\v1;

    class Module extends \yii\base\Module
{
    /**
     * {@inheritdoc}
     */
    public $controllerNamespace = 'api\modules\v1\controllers';

    /**
     * {@inheritdoc}
     */
    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }
}

user controller:
amespace api\modules\v1\controllers;

use yii\rest\ActiveController;

class UserController extends ActiveController
{
public $modelClass = ‘api\modules\v1\models\User’;

public function actionDefault()
{
    echo 'tesssst';
}

public function actionTest()
{
    return 'tesssst';
}

}

Error handler in main.php does work though ( ‘errorAction’ => ‘v1/default/error’,)

I’ve been trying to acces controller as localhost /api/web/v1/user/test, localhost/api/v1/user/test, localhost/api/web/v1/users, localhost/api/v1/users… it’s always the same…

upd: also I have Yii::setAlias(’@api’, dirname(dirname(DIR)) . ‘/api’); in common/config/bootstrap.php and parsers ‘application/json’ => ‘yii\web\JsonParser’, in api/config/main-loacal.php