I made a very basic API with 2 simple controllers like this one
<?php
namespace api\controllers;
use yii\rest\ActiveController;
class TimeController extends ActiveController
{
public $modelClass = 'api\models\Time';
}
It works locally but when I try to run it on production I only get a XML with error 500
<response>
<name>Internal Server Error</name>
<message>An internal server error occurred.</message>
<code>0</code>
<status>500</status>
</response>
I tried to add a regular controller inside my api application and it works fine.
Here is my api/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',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the api
'name' => 'advanced-api',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
// 'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'pluralize' => false,
'class' => 'yii\rest\UrlRule',
'controller' => 'time',
'tokens' => [
'{id}' => '<id:\\w+>'
]
],
[
'pluralize' => false,
'class' => 'yii\rest\UrlRule',
'controller' => 'jogo',
'tokens' => [
'{id}' => '<id:\\w+>'
]
]
],
],
],
'params' => $params,
];