You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.3 KiB

<?php
namespace api\controllers;
use yii\filters\auth\HttpBearerAuth;
use yii\helpers\ArrayHelper;
use yii\rest\ActiveController;
/**
* @author iron
* @email weiriron@gmail.com
*/
class CommonController extends ActiveController
{
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'authenticatior' => [
'class' => HttpBearerAuth::className(),
'except' => [],
]
]);
}
public function actions()
{
$action = parent::actions();
unset($action['delete']);
unset($action['create']);
unset($action['update']);
$action['index'] = [
'class' => 'yii\rest\IndexAction',
'checkAccess' => [$this, 'checkAccess'],
'modelClass' => $this->modelClass,
'dataFilter' => $this->getFilter()
];
return $action;
}
protected function getFilter()
{
$data = \Yii::$app->request->getBodyParams();
$data['user'] = true;
\Yii::$app->request->setBodyParams($data);
$filter = ['class' => 'yii\data\ActiveDataFilter',
'filter' => ['user_id' => \Yii::$app->user->getId()],
'searchModel' => ['class' => 'antgoods\goods\models\searchs\GoodsSearch']];
return $filter;
}
}