您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DeleteAction.php 940B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. }