Answer the question
In order to leave comments, you need to log in
Rest Api on yii2 in Json format?
I decided to make within the site, the controller responsible for the rest of the action.
How can I reduce all answers to one format that would simply return data and without unnecessary information, but within one controller. Current way
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => QueryParamAuth::className(),
];
$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
return $behaviors;
}
{"name":"Unauthorized","message":"You are requesting with an invalid credential.","code":0,"status":401,"type":"yii\\web\\UnauthorizedHttpException"}
Answer the question
In order to leave comments, you need to log in
Try to put YII_DEBUG = false in the index file.
You can still try to do as it is written here , but this is for all controllers at once.
public $serializer ='frontend\modules\v2\component\CustomSerializer',
public function actionSpecialFoApi()
{
if(rest_responce == true) {
/** @var \frontend\modules\v2\component\ApicoSerializer $serializer */
return Yii::createObject($this->serializer)->serialize($data);
return; //возможно это может надо???
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question