Reputation: 3659
Trying to create API app (based on RESTFull services) using Yii2 Advanced template. Created subdomain api.domain.com for this purpose.
The directory structure looks like this:
The problem is, when I try to send GET request to api.domain.com/users
getting following response:
{
"name": "Not Found",
"message": "Page not found.",
"code": 0,
"status": 404,
"type": "yii\web\NotFoundHttpException",
"previous": {
"name": "Invalid Route",
"message": "Unable to resolve the request \"user/index\".",
"code": 0,
"type": "yii\base\InvalidRouteException"
}
}
Here is config file:
https://gist.github.com/d1930b6bf20e3d50fe63
Here is controller (which is located in Controllers folder):
https://gist.github.com/anonymous/180a7e791e879570e0f4
what am I doing wrong?
Upvotes: 2
Views: 934
Reputation: 462
3 things:
Add rule 'extraPatterns' in main.php:urlManager if need be. Ex:
['class' => 'yii\rest\UrlRule', 'controller' => 'v1/report', 'extraPatterns'=>['analytics' => 'analytics', 'report' => 'report']],
Upvotes: 0
Reputation: 23290
Make sure that, you added api
application's path into bootstrap.php
in common folder. It must look like:
<?php
Yii::setAlias('common', dirname(__DIR__));
Yii::setAlias('frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('api', dirname(dirname(__DIR__)) . '/api'); <-- this line
BTW, File located in common/config/bootstrap.php
Upvotes: 5