xihrni / yii2-behavior-time
For automatic updating of database table creation, update, and delete fields in the model.
Installs: 34
Dependents: 2
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2025-06-05 18:33:13 UTC
README
Introduction
用于自动更新模型中数据库表的创建、更新和删除字段
Install
$ composer require xihrni/yii2-behavior-time
Demo
CREATE TABLE `xi_article` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL DEFAULT '', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
<?php namespace app\models; use xihrni\yii2\behaviors\TimeBehavior; class Article extends \yii\db\ActiveRecord { public static function tableName() { return '{{%article}}'; } public function behaviors() { return array_merge(parent::behaviors(), [ 'time' => [ 'class' => TimeBehavior::className(), ], ]); } }