E
E
Express7772016-02-22 10:08:28
Yii
Express777, 2016-02-22 10:08:28

What is wrong with Setting read-only property: yii\web\Application::response?

There is a simple code in the controller, the task of which is to give data in the form of JSON

public function actionGroupList($id){
    Yii::$app->response = Response::FORMAT_JSON;
    $groupList = CatalogHelper::getGroupList($id);

    return $groupList;
  }

Which throws this error:
Invalid Call – yii\base\InvalidCallException

Setting read-only property: yii\web\Application::response

Although in the documentation, it is written that way
public function actionInfo()
{
    \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
    return [
        'message' => 'hello world',
        'code' => 100,
    ];
}

www.yiiframework.com/doc-2.0/guide-runtime-respons...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-02-22
@Express777

Yii::$app->response =
and
kagbe are not the same thing.
and the error speaks for itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question