You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 line
940B

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