Pergunta

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.

Foi útil?

Solução 2

Add this in actionDelete of your controller.

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

Outras dicas

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)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top