1 | <?php |
||
2 | /** |
||
3 | * @link https://www.yiiframework.com/ |
||
4 | * @copyright Copyright (c) 2008 Yii Software LLC |
||
5 | * @license https://www.yiiframework.com/license/ |
||
6 | */ |
||
7 | |||
8 | namespace yii\rest; |
||
9 | |||
10 | use Yii; |
||
11 | use yii\web\ServerErrorHttpException; |
||
12 | |||
13 | /** |
||
14 | * DeleteAction implements the API endpoint for deleting a model. |
||
15 | * |
||
16 | * For more details and usage information on DeleteAction, see the [guide article on rest controllers](guide:rest-controllers). |
||
17 | * |
||
18 | * @author Qiang Xue <[email protected]> |
||
19 | * @since 2.0 |
||
20 | */ |
||
21 | class DeleteAction extends Action |
||
22 | { |
||
23 | /** |
||
24 | * Deletes a model. |
||
25 | * @param mixed $id id of the model to be deleted. |
||
26 | * @throws ServerErrorHttpException on failure. |
||
27 | */ |
||
28 | public function run($id) |
||
29 | { |
||
30 | $model = $this->findModel($id); |
||
31 | |||
32 | if ($this->checkAccess) { |
||
33 | call_user_func($this->checkAccess, $this->id, $model); |
||
34 | } |
||
35 | |||
36 | if ($model->delete() === false) { |
||
37 | throw new ServerErrorHttpException('Failed to delete the object for unknown reason.'); |
||
38 | } |
||
39 | |||
40 | Yii::$app->getResponse()->setStatusCode(204); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
41 | } |
||
42 | } |
||
43 |