Answer the question
In order to leave comments, you need to log in
Is it possible in Yii2 to specify a JSON parser for a specific action/actions?
public function behaviors()
{
return [
'verbs' => [
'class' => \yii\filters\VerbFilter::className(),
'actions' => [
'index' => ['GET'],
'truck' => ['POST', "DELETE"],
'polygon' => ['POST', "DELETE"],
'marker' => ['POST', "DELETE"],
'line-string' => ['POST', "DELETE"],
],
],
];
}
Yii::$app->request->parsers = [
'application/json' => 'yii\web\JsonParser'
];
Yii::$app->response->format = Response::FORMAT_JSON;
Answer the question
In order to leave comments, you need to log in
public function behaviors()
{
return [
[
'class' => 'yii\filters\ContentNegotiator',
'only' => ['view', 'index'], // in a controller
// if in a module, use the following IDs for user actions
// 'only' => ['user/view', 'user/index']
'formats' => [
'application/json' => Response::FORMAT_JSON,
],
'languages' => [
'en',
'de',
],
],
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question