Blame view

vendor/yiisoft/yii2/rest/DeleteAction.php 940 Bytes
abf1649b   andryeyev   Чистая установка ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  <?php
  /**
   * @link http://www.yiiframework.com/
   * @copyright Copyright (c) 2008 Yii Software LLC
   * @license http://www.yiiframework.com/license/
   */
  
  namespace yii\rest;
  
  use Yii;
  use yii\web\ServerErrorHttpException;
  
  /**
   * DeleteAction implements the API endpoint for deleting a model.
   *
   * @author Qiang Xue <qiang.xue@gmail.com>
   * @since 2.0
   */
  class DeleteAction extends Action
  {
      /**
       * Deletes a model.
       * @param mixed $id id of the model to be deleted.
       * @throws ServerErrorHttpException on failure.
       */
      public function run($id)
      {
          $model = $this->findModel($id);
  
          if ($this->checkAccess) {
              call_user_func($this->checkAccess, $this->id, $model);
          }
  
          if ($model->delete() === false) {
              throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
          }
  
          Yii::$app->getResponse()->setStatusCode(204);
      }
  }