-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any demo/example of how to use this extension? #26
Comments
I obviously saw the README but that's not really something very helpful, there's no logic in that controller and not a fully working example. |
@gigo6000 |
@mtangoo all I ask is an example of how this extension can be used. This is how I managed to use the serializer:
Hope it helps someone else. |
I think you are almost there. According to docs, you need to do one more thing for the controller and two things on the models: On Controller define public attribute serializer public $serializer = [
'class' => 'tuyakhov\jsonapi\Serializer',
'pluralize' => false, // makes {"type": "user"}, instead of {"type": "users"}
]; Then in models
This will allow your method to be as clean as Controllerclass UserController extends Controller
{
public $serializer = [
'class' => 'tuyakhov\jsonapi\Serializer',
'pluralize' => false, // makes {"type": "user"}, instead of {"type": "users"}
];
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'contentNegotiator' => [
'class' => ContentNegotiator::className(),
'formats' => [
'application/vnd.api+json' => Response::FORMAT_JSON,
],
]
]);
}
public function actionShow()
{
$id = Yii::$app->getRequest()->getQueryParam('id');
return User::findOne($id);
}
} Modelclass User extends ActiveRecord implements ResourceInterface
{
use ResourceTrait;
} HTH |
Hi. Thank you for it.
|
Hi, thanks for your work on this. I'm trying to implement your extension but can't find any example code to play with and I can't figure out how to use it looking at the code. Thanks
The text was updated successfully, but these errors were encountered: