Soft delete behavior for Yii2
PHP
Latest commit efa5f6b Feb 21, 2017 @cornernote committed on GitHub Update SoftDeleteQueryBehavior.php

README.md

Yii2 Soft Delete

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Soft delete behavior for Yii2.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require cornernote/yii2-softdelete "*"

or add

"cornernote/yii2-softdelete": "*"

to the require section of your composer.json file.

Usage

In your ActiveRecord class:

public function behaviors() {
    return [
        \cornernote\softdelete\SoftDeleteBehavior::className(),
        // or
        [
            'class' => \cornernote\softdelete\SoftDeleteBehavior::className(),
            'attribute' => 'deleted_time',
            'value' => new \yii\db\Expression('NOW()'), // for sqlite use - new \yii\db\Expression("date('now')")
        ],
    ];
}

In your ActiveQuery class:

public function behaviors() {
    return [
        \cornernote\softdelete\SoftDeleteQueryBehavior::className(),
        // or
        [
            'class' => \cornernote\softdelete\SoftDeleteQueryBehavior::className(),
            'attribute' => 'deleted_time',
        ],
    ];
}