The class of the ActiveRecord should be specified via [[modelClass]], which must implement ActiveRecordInterface. By default, the following actions are supported: - index: list of models - view: return the details of a model - create: create a new model - update: update an existing model - delete: delete an existing model - options: return the allowed HTTP methods You may disable some of these actions by overriding ActiveController::actions and unsetting the corresponding actions. To add a new action, either override ActiveController::actions by appending a new action class or write a new action method. Make sure you also override ActiveController::verbs to properly declare what HTTP methods are allowed by the new action. You should usually override ActiveController::checkAccess to check whether the current user has the privilege to perform the specified action against the specified model.
С версии: 2.0
Автор: Qiang Xue (qiang.xue@gmail.com)
Наследование: extends Controller
Пример #1
0
 public function actions()
 {
     $actions = parent::actions();
     // personalizza il data provider preparation con il metodo "prepareDataProvider()"
     $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
     return $actions;
 }
Пример #2
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator']['class'] = QueryParamAuth::className();
     $behaviors['authenticator']['tokenParam'] = 'access_token';
     return $behaviors;
 }
Пример #3
0
 public function actions()
 {
     $actions = parent::actions();
     $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
     //$actions['create']['run'] = [$this, 'run1'];
     return $actions;
 }
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className(), 'except' => ['options']];
     $behaviors['corsFilter'] = ['class' => Cors::className()];
     return $behaviors;
 }
Пример #5
0
 public function actions()
 {
     $actions = parent::actions();
     unset($actions['index']);
     unset($actions['view']);
     return $actions;
 }
Пример #6
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className()];
     $behaviors['contentNegotiator'] = ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON]];
     return $behaviors;
 }
Пример #7
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'except' => ['login', 'error'], 'authMethods' => [HttpBearerAuth::className()]];
     unset($behaviors['rateLimiter']);
     return $behaviors;
 }
Пример #8
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['rateLimiter'] = ['class' => RateLimiter::className(), 'enableRateLimitHeaders' => false];
     $behaviors['contentNegotiator'] = ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON]];
     return $behaviors;
 }
Пример #9
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON; //setting JSON as default reply
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [HttpBasicAuth::className(), HttpBearerAuth::className(), QueryParamAuth::className()]];
     return $behaviors;
 }
Пример #10
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     /*
     // test with basic auth which can be set in params
     $behaviors['authenticator'] = [
     'class' => HttpBasicAuth::className(),
     'auth'  => function ($username, $password) {
         if ($username==\Yii::$app->params['HttpBasicAuth']['username'] && $password==\Yii::$app->params['HttpBasicAuth']['password']) {
             return new User();
         } else {
             return null;
         }
     }];
     */
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [HttpBasicAuth::className(), QueryParamAuth::className()]];
     /*
     //set response header to application/json only
     $behaviors['contentNegotiator'] = [
             'class' => ContentNegotiator::className(),
             'formats' => [
                 'application/json' => Response::FORMAT_JSON,
     //            'application/xml' => Response::FORMAT_XML,
             ],
     ];
     */
     return $behaviors;
 }
Пример #11
0
 public function actions()
 {
     $actions = parent::actions();
     unset($actions['index'], $actions['update'], $actions['create'], $actions['delete'], $actions['view']);
     //unset($actions['update'], $actions['create'], $actions['delete'], $actions['view']);
     return $actions;
 }
 public function actions()
 {
     $actions = parent::actions();
     // customize the data provider preparation with the "prepareDataProvider()" method
     $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
     return $actions;
 }
Пример #13
0
 public function behaviors()
 {
     $self = self::className();
     $behaviors = parent::behaviors();
     $behaviors['access'] = ['class' => \app\components\filters\AccessControl::className(), 'rules' => $self::getAccessRules()];
     return $behaviors;
 }
Пример #14
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['verbs'] = ['class' => VerbFilter::className(), 'actions' => ['indexWithQuote' => ['get']]];
     $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()];
     return $behaviors;
 }
Пример #15
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     // enabled HttpBearerAuth
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className()];
     return $behaviors;
 }
Пример #16
0
 /**
  * Override the base actions in order to support some enhancements of actions
  * by default for all active controllers.
  * @see \yii\rest\ActiveController::actions()
  */
 public function actions()
 {
     $actions = parent::actions();
     $actions['index']['class'] = '\\luya\\rest\\actions\\IndexAction';
     $actions['delete']['class'] = '\\luya\\rest\\actions\\DeleteAction';
     return $actions;
 }
Пример #17
0
 /**
  * Some rules in this controller
  * @return Rules behaviors
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => QueryParamAuth::className(), 'tokenParam' => 'token'];
     unset($behaviors['rateLimiter']);
     return $behaviors;
 }
Пример #18
0
 public function actions()
 {
     $actions = parent::actions();
     // remove parent's control over create
     unset($actions['create']);
     return $actions;
 }
 public function actions()
 {
     $actions = parent::actions();
     unset($actions['view']);
     $actions1 = ArrayHelper::merge(['actionPedido'], $actions);
     return $actions1;
 }
Пример #20
0
 /**
  * 行为扩展
  * @return array
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     //        $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_HTML;
     $behaviors['contentNegotiator']['formats'] = ['application/json' => Response::FORMAT_JSON];
     return $behaviors;
 }
 public function actions()
 {
     $actions = parent::actions();
     // disable the "delete" and "create" actions
     unset($actions['delete'], $actions['create']);
     return $actions;
 }
Пример #22
0
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     // $behaviors['authenticator'] = [
         // 'class' => HttpBasicAuth::className(),
     // ];
     return $behaviors;
 }
Пример #23
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     // send Authorization : Basic base64(token:) in header
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()];
     $behaviors['verbs'] = ['class' => VerbFilter::className(), 'actions' => ['index' => ['GET'], 'view' => ['GET'], 'create' => ['PUT'], 'update' => ['POST', 'PATCH'], 'delete' => ['DELETE']]];
     return $behaviors;
 }
Пример #24
0
 public function actions()
 {
     $actions = parent::actions();
     // change index class
     $actions['index']['class'] = '\\admin\\rest\\IndexAction';
     $actions['delete']['class'] = '\\admin\\rest\\DeleteAction';
     return $actions;
 }
Пример #25
0
 /**
  * Переобределяем свои действия
  * @return array
  */
 public function actions()
 {
     $actions = parent::actions();
     unset($actions['index']);
     //unset($actions['update']);
     $this->model = new $this->modelClass();
     return $actions;
 }
Пример #26
0
 public function _checkAccess($action, $model = null, $params = array())
 {
     var_dump($action);
     var_dump($model);
     var_dump($params);
     die;
     parent::checkAccess($action, $model, $params);
 }
Пример #27
0
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return true;
 }
Пример #28
0
 /**
  * @inheritdoc
  */
 public function afterAction($action, $result)
 {
     $result = parent::afterAction($action, $result);
     $result = $this->serializeData($result);
     if (!isset($result['code'])) {
         return ApiHelper::successResponse($result);
     }
     return $result;
 }
Пример #29
0
 /**
  * @return array
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBasicAuth::className(), 'auth' => function ($username, $password) {
         $user = User::findByLogin($username);
         return $user->validatePassword($password) ? $user : null;
     }], HttpBearerAuth::className(), QueryParamAuth::className()]];
     return $behaviors;
 }
Пример #30
-2
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className(), 'only' => ['dashboard']];
     $behaviors['access'] = ['class' => AccessControl::className(), 'only' => ['dashboard'], 'rules' => [['actions' => ['dashboard'], 'allow' => true, 'roles' => ['@']]]];
     return $behaviors;
 }