Domanda

I have a yii2 project, i've used gii to generate crud operations for a model named account.

now i want to change(or add a new one) the delete function so that it doesn't delete the record from the database but instead flag it as deleted, and i'm not sure where to make my changes.

È stato utile?

Soluzione 2

Add this in actionDelete of your controller.

$model->deleted = 1;
$model->save();

Altri suggerimenti

You should do this in model's code itself, by overriding beforeDelete() event. Something like this:

public function beforeDelete()
{
    if (parent::beforeDelete()) {
        $this->deleted = true;
        $this->save();

        return false;
    } else {
        return false;
    }
}

(written from my memory, not tested, but should work)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top