Answer the question
In order to leave comments, you need to log in
How to do different serialization of data for two different actions in yii2 REST API?
Hello.
Below is the code for my controller with two actions.
I need to use one serializer for one action and another for the second one.
How it is better to implement it?
Thank you for your attention.
namespace app\modules\v1\controllers;
use yii;
use yii\web\BadRequestHttpException;
class PortfolioController extends ActiveController
{
public $modelClass = Portfolio::class;
public $serializer = [
'class' => 'common\components\serializers\PortfolioSerializer',
];
public function actionIndex()
{
return $data;
}
public function actionAdd()
{
return $data;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question