How to use work behavior as RESTful?

I follow the * instructions on how to create a RESTful service with Yii2, but the behavior method throws an error:

Response content must not be an array.

If I remove the behavior method, I get the JSON response that I expect. I tried to remove the behavior method after reading another post **.

However, I am a little unfamiliar with the behavior. Can we use behavior with Yii2 with REST or is this a bug? I would really appreciate it if someone could shed light on this.

* http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html ** http://www.yiiframework.com/forum/index.php/topic/60432-rest-api- failing-with-behaviors /

+4
source share
1 answer

, behaviors(). , . , , . , behaviors() :

public function behaviors() {
    return ArrayHelper::merge(parent::behaviors(), [
                'verbs' => [
                    'class' => VerbFilter::className(),
                    'actions' => [
                        'delete' => ['post'],
                    ],
                ],
    ]);
}

use yii\helpers\ArrayHelper .

+8

All Articles