forked from Insolita/yii2-fractal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCategoryController.php
executable file
·75 lines (72 loc) · 2.65 KB
/
CategoryController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace app\controllers;
use app\models\Category;
use insolita\fractal\actions\CreateAction;
use insolita\fractal\actions\ListAction;
use insolita\fractal\actions\UpdateAction;
use insolita\fractal\actions\ViewAction;
use insolita\fractal\actions\ViewRelationshipAction;
use insolita\fractal\JsonApiController;
use app\transformers\CategoryTransformer;
use insolita\fractal\providers\CursorActiveDataProvider;
use yii\rest\DeleteAction;
use yii\rest\OptionsAction;
class CategoryController extends JsonApiController
{
public function actions()
{
return [
'bad-config'=>[
'class' => ViewAction::class,
'transformer'=>CategoryTransformer::class,
'resourceKey'=>'category'
],
'create'=>[
'class' => CreateAction::class,
'modelClass'=>Category::class,
'viewRoute'=>'view',
//'scenario'=>'create',
'resourceKey'=>'category',
'transformer'=>CategoryTransformer::class,
],
'view'=>[
'class' => ViewAction::class,
'modelClass'=>Category::class,
'resourceKey'=>'category',
// 'findModel'=>function($id){
// return Category::find()->where(['active'=>true, 'id'=>$id])->one();
// }
//'transformer'=>CategoryTransformer::class,
],
'update'=>[
'class' => UpdateAction::class,
'modelClass'=>Category::class,
'resourceKey'=>'category',
// 'findModel'=>function($id){
// return Category::find()->where(['active'=>true, 'id'=>$id])->one();
// }
//'transformer'=>CategoryTransformer::class,
],
'delete'=>[
'class' => DeleteAction::class,
'modelClass'=>Category::class,
],
'list'=>[
'class' => ListAction::class,
'modelClass'=>Category::class,
'transformer'=>CategoryTransformer::class,
'resourceKey'=>'category'
],
'related-posts'=>[
'class' => ViewRelationshipAction::class,
'modelClass' => Category::class,
'relationName'=>'posts',
'resourceKey'=>'posts',
'dataProvider'=>['class' => CursorActiveDataProvider::class]
],
'options' => [
'class' => OptionsAction::class,
],
];
}
}