我刚刚使用 Yii2 构建了一个应用程序作为 Flutter App 的后端
所以..我创建了一个模块/api文件夹,并在其中创建了控制器,就像这样
<?php
namespace app\modules\api\controllers;
use yii\web\Controller;
use yii\rest\ActiveController;
class AdController extends ActiveController
{
public $modelClass = 'app\models\Ad';
}
它工作正常,但它返回 XML
我在 web.php 中尝试过
'components' => [
'response' => [
'format' => \yii\web\Response::FORMAT_JSON,
],
],
和
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
但它仍然返回 XML
更新
当我使用
'urlManager' => [
....
'enableStrictParsing' => true,
...
]
它给了我Not Found (#404)