Exemple #1
0
 /**
  * @param $id
  * @return ActiveRecord
  * @throws \yii\web\NotFoundHttpException
  */
 public function run($id)
 {
     /** @var ActiveRecord $model */
     $model = new $this->modelClass();
     $model = $model->findOne(['id' => $id]);
     if (empty($model)) {
         HttpError::the404('Not found');
     }
     return $model;
 }
Exemple #2
0
 /**
  * @param $id
  * @throws ServerErrorHttpException
  * @throws \Exception
  * @throws \yii\web\NotFoundHttpException
  */
 public function run($id)
 {
     /** @var \yii\db\ActiveRecord $model */
     $model = new $this->modelClass();
     $model = $model->findOne(['id' => $id]);
     if (empty($model)) {
         HttpError::the404('Not found');
     }
     if ($model->delete() === false) {
         throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
     }
     Yii::$app->getResponse()->setStatusCode(204);
 }
Exemple #3
0
 /**
  * @param $id
  * @return \yii\db\ActiveRecord
  * @throws ServerErrorHttpException
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\web\NotFoundHttpException
  */
 public function run($id)
 {
     /** @var \yii\db\ActiveRecord $model */
     $model = new $this->modelClass();
     $model = $model->findOne(['id' => $id]);
     if (empty($model)) {
         HttpError::the404('Not found');
     }
     $model->load(Yii::$app->getRequest()->getBodyParams(), '');
     if ($model->save() === false && !$model->hasErrors()) {
         throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
     }
     return $model;
 }