A
A
AR2017-03-04 14:19:56
Yii
AR, 2017-03-04 14:19:56

Yii2: Why isn't an array returned?

Good afternoon.
There is a function that should return an object from the partner table as an array.

public function actionGetPartner($id){
        $partner = Partner::find()->where(['id' => (int)$id])->asArray()->one();
        return $partner;
    }

But for some reason the error is:
Invalid Parameter - yii\base\InvalidParamException
Response content must not be an array.
If you do not return but wardump, then the array is normally printed out and everything is ok.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-03-04
@amio

But for some reason the error is:
Invalid Parameter - yii\base\InvalidParamException
Response content must not be an array.

Because the server response cannot be an array. That's how it's written. Return as json, that's what it's for.

A
AlexKuznec, 2017-03-04
@AlexKuznec

If it's just a function, remove "action" from the name. Actions must return the server's response as a string (usually html or json).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question