|
| 1 | +<?php |
| 2 | +namespace app\controllers\base; |
| 3 | + |
| 4 | +use insolita\fractal\JsonApiController; |
| 5 | +use Yii; |
| 6 | + |
| 7 | +abstract class PetController extends JsonApiController |
| 8 | +{ |
| 9 | + public function actions() |
| 10 | + { |
| 11 | + return [ |
| 12 | + 'view' => [ |
| 13 | + 'class' => \insolita\fractal\actions\ViewAction::class, |
| 14 | + 'checkAccess' => [$this, 'checkAccess'], |
| 15 | + 'transformer' => \app\transformers\PetTransformer::class, |
| 16 | + 'modelClass' => \app\models\Pet::class, |
| 17 | + 'resourceKey' => 'pets', |
| 18 | + 'findModel' => null |
| 19 | + ], |
| 20 | + 'delete' => [ |
| 21 | + 'class' => \insolita\fractal\actions\DeleteAction::class, |
| 22 | + 'checkAccess' => [$this, 'checkAccess'], |
| 23 | + 'modelClass' => \app\models\Pet::class, |
| 24 | + 'findModel' => null |
| 25 | + ], |
| 26 | + 'update' => [ |
| 27 | + 'class' => \insolita\fractal\actions\UpdateAction::class, |
| 28 | + 'checkAccess' => [$this, 'checkAccess'], |
| 29 | + 'transformer' => \app\transformers\PetTransformer::class, |
| 30 | + 'modelClass' => \app\models\Pet::class, |
| 31 | + 'resourceKey' => 'pets', |
| 32 | + 'findModel' => null, |
| 33 | + 'allowedRelations'=>[], |
| 34 | + 'scenario' => 'default' |
| 35 | + ], |
| 36 | + 'options' => [ |
| 37 | + 'class' => \yii\rest\OptionsAction::class, |
| 38 | + ], |
| 39 | + ]; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Checks the privilege of the current user. |
| 44 | + * |
| 45 | + * This method checks whether the current user has the privilege |
| 46 | + * to run the specified action against the specified data model. |
| 47 | + * If the user does not have access, a [[ForbiddenHttpException]] should be thrown. |
| 48 | + * |
| 49 | + * @param string $action the ID of the action to be executed |
| 50 | + * @param object $model the model to be accessed. If null, it means no specific model is being accessed. |
| 51 | + * @param array $params additional parameters |
| 52 | + * @throws \yii\web\ForbiddenHttpException if the user does not have access |
| 53 | + */ |
| 54 | + abstract public function checkAccess($action, $model = null, $params = []); |
| 55 | +} |
0 commit comments