For more details and usage information on Action, see the guide article on rest controllers.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Action
Exemplo n.º 1
0
 public function init()
 {
     $this->modelClass = UserProfile::className();
     $this->findModel = UserController::className() . '::' . UserController::METHOD_FIND_MODEL;
     $this->checkAccess = UserController::className() . '::' . UserController::METHOD_CHECK_ACCESS;
     parent::init();
 }
Exemplo n.º 2
0
 /**
  * @return bool
  * @throws \yii\web\ForbiddenHttpException
  */
 public function beforeRun()
 {
     if ($this->needAuthorize && Yii::$app->user->isGuest) {
         HttpError::the403();
     }
     return parent::beforeRun();
 }
Exemplo n.º 3
0
 /**
  * @return string|array
  */
 private function getRulesForAction()
 {
     if ($this->action->controller instanceof ActiveController) {
         return $this->getRulesForActiveAction($this->action);
     }
     if (!method_exists($this->action, 'rules')) {
         return '';
     }
     return $this->action->rules();
 }
Exemplo n.º 4
0
 public function findModel($id = null)
 {
     if (is_null($id)) {
         $modelClass = $this->modelClass;
         $emptyPrimaryKey = array_flip($modelClass::primaryKey());
         $primaryKey = array_merge($emptyPrimaryKey, array_intersect_key(Yii::$app->getRequest()->getQueryParams(), $emptyPrimaryKey));
         $id = implode(',', array_values($primaryKey));
     }
     return parent::findModel($id);
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $params = Yii::$app->request->queryParams;
     if ($this->expectedParams($params) === false) {
         throw new InvalidConfigException("unexpected configurations.");
     }
     $this->relativeClass = $params['relativeClass'];
     $this->relationName = $params['relationName'];
     $this->linkAttribute = $params['linkAttribute'];
     $this->relative_id = $params[$this->linkAttribute];
 }
 /**
  * check request for errors and load items
  */
 public function init()
 {
     if (!$this->enable) {
         throw new MethodNotAllowedHttpException("Method Not Allowed");
     }
     $this->items = Yii::$app->getRequest()->getBodyParam($this->property);
     if (!is_array($this->items)) {
         throw new BadRequestHttpException("{$this->property} must be array");
     }
     if (count($this->items) > $this->limit) {
         throw new BadRequestHttpException("Request Entity Too Large", 413);
     }
     parent::init();
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function findModel($id)
 {
     $id = Uuid::str2uuid($id);
     return parent::findModel($id);
 }
Exemplo n.º 8
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->controller instanceof ActiveController || $this->controller instanceof \yii\rest\ActiveController) {
         if ($this->modelClass === null) {
             $this->modelClass = $this->controller->modelClass;
         }
         if ($this->checkAccess === null) {
             $this->checkAccess = [$this->controller, 'checkAccess'];
         }
     }
     if ($this->viewName === null) {
         $this->viewName = $this->id;
     }
     parent::init();
 }
Exemplo n.º 9
0
 /**
  *
  */
 public function init()
 {
     parent::init();
 }