Yii2 basic tempalte - Rest api not working

hi,

I tried this link.

I downloaded a new version of yii2 basic. Then created a folder called api. My directory structure is like this

Reachon is my basic folder name. When i try to run this url [size="2"]http://192.168.1.3/~...web/v1/bookings[/size]

i get an error like this

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

this is my api. php




<?php

 

$db 	= require(__DIR__ . '/../../config/db.php');

$params = require(__DIR__ . '/params.php');

 

$config = [

    'id' => 'basic',

    'name' => 'TimeTracker',

    // Need to get one level up:

    'basePath' => dirname(__DIR__).'/..',

    'bootstrap' => ['log'],

    'components' => [

        'request' => [

            // Enable JSON Input:

            'parsers' => [

                'application/json' => 'yii\web\JsonParser',

            ]

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                 	// Create API log in the standard log dir

                 	// But in file 'api.log':

                    'logFile' => '@app/runtime/logs/api.log',

                ],

            ],

        ],

        'urlManager' => [

            'enablePrettyUrl' => true,

            'enableStrictParsing' => true,

            'showScriptName' => false,

            'rules' => [

                ['class' => 'yii\rest\UrlRule', 'controller' => ['v1/bookings','v1/time']],

            ],

        ], 

        'db' => $db,

    ],

    'modules' => [

        'v1' => [

            'class' => 'app\api\modules\v1\Module',

        ],

    ],

    'params' => $params,

];

 

return $config;

in controllers folder i have BookingsController.php





<?php

namespace app\api\modules\v1\controllers;

 

use yii\rest\ActiveController;

 

class BookingsController extends ActiveController

{

    // We are using the regular web app modules:

    public $modelClass = 'app\models\Bookings';

}



Have you try with pretty url disabled?

hi when i tried disabling pretty url i got this error

[color=#E51717][font=inherit][size=2]Invalid Configuration[/size][/font][/color] – yii\base\InvalidConfigException

User::identityClass must be set.

ok, this is another kind of error.

I suggest you to try disable pretty url because often with restful api there are problems.

So try to check as well your .htaccess in your root directory and in your "web" directory. And also your httpd.conf (yes only if you have Apache web server) that is enabled to rewriting rules.

About the new error i don’t have many element, (the file and the call that make the error) but i think you are using a class User not definied well:


class User extends \yii\base\Object implements \yii\web\IdentityInterface

try to set enableStrictParsing to false