调用时出现未定义参数错误 Yii::$app->params['status']
我已经为 Web 服务创建了 api 文件夹,在这个文件夹中我有api/controllers/UsersController.php. 我Yii::$app->params['status']在此控制器的操作之一中调用它,但收到未定义的错误。
这是我的 api/config/main.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' => 'api',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'api\controllers',
'bootstrap' => ['log'],
'components' => [
'user' => [
'identityClass' => 'common\models\Users',
'enableAutoLogin' => false,
'idParam' => '_api'
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'response' => [
'class' => 'yii\web\Response',
'on beforeSend' => function ($event) {
$response = $event->sender;
if ($response->data !== null && Yii::$app->request->get('suppress_response_code')) {
$response->data = [
'success' => $response->isSuccessful,
'data' => $response->data,
];
$response->statusCode = 200;
}
},
],
当我犯错时请告诉别人。