A
A
agent11562016-09-21 15:19:59
Yii
agent1156, 2016-09-21 15:19:59

How to remove deletion error?

$del = Yii::$app->request->get('del');
        if (!empty($del)) {
            $del_org = Comments::findOne($del);
            $del_org->delete();

With this script and the GET parameter, I remove the comments. But after removing the GET parameter remains in the line, and if you refresh the page with the same GET parameter, an error pops up. Please tell me how to check before $del_org->delete(). Or how to remove GET using $_SERVER, in the last option I did not succeed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2016-09-21
@agent1156

Try like this:

$del = Yii::$app->request->get('del');
        if (!empty($del)) {
            $del_org = Comments::findOne($del);
            if ($del_org->delete()) {
                $this->redirect(...url...); // Это работает в контроллере
            }
        }

But in general, it is customary to do the deletion at least through POST, and as expected - through a DELETE request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question