object = Yii::createObject([ 'class' => $this->className, ]); } /** * @return array */ public function behaviors() { return ArrayHelper::merge(parent::behaviors(), [ 'authenticatior' => [ 'class' => HttpBearerAuth::className(), 'except' => ['token'], ] ]); } public function actions() { $action = parent::actions(); unset($action['create']); unset($action['update']); unset($action['index']); return $action; } protected function getFilter() { return []; } /** * @param string $action * @param null $model * @param array $params * @throws NotFoundHttpException * 权限控制 */ public function checkAccess($action, $model = null, $params = []) { if ($model && isset($model->user_id) && $model->user_id !== Yii::$app->user->getId()) { switch ($action) { case 'view': $message = '您无权访问该数据'; break; case 'delete': $message = '您无权删除该数据'; break; default: $message = '无相关权限'; } throw new NotFoundHttpException($message); } } }