Hi guys, i’ve been trying to get the restful api working without success. I have followed these tutorials: yiiframework-guide-rest-quick-start, budiirawan.com/setup-restful-api-yii2/, and www.diggin-data.de/dd-cms/blog/post/view/id/1004/name/Creating+a+REST+API+for+Yii2-basic-template, but keep getting Status 500 Internal Server Error. (I’m running Xampp/Win7 with mod_rewrite active).
Directory structure:
app
-api -> index.php, .htaccess
–config -> main.php
–modules -> Module.php
—v1
----controllers -> CountryController.php
----models -> Country.php
-assets
-controllers
-models
CountryController.php
namespace app\api\modules\v1\controllers;
use yii\rest\ActiveController;
class CountryController extends ActiveController {
public $modelClass = 'app\api\modules\v1\models\Country';
//public $modelClass = 'app\models\Country';
}
//both configs of $modelClass gave the same Status 500 error
api/config/main.php
$db = require(DIR . ‘/../../config/db.php’);
$params = require(DIR . ‘/params.php’);
return [
'id' => 'countryapp-api',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'modules' => [
'v1' => [
'basePath' => '@app/api/modules/v1',
'class' => 'app\api\modules\v1\Module' // here is our v1 modules
]
],
'components' => [
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => false,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/country',
'tokens' => [
'{id}' => '<id:\\w+>'
]
]
],
]
],
'params' => $params,
];
Please point me in the right direction. Thanks