mongosoft / yii2-mongodate-behavior
MongoDate 行为扩展适用于 Yii 2
0.2.0
2016-07-08 13:21 UTC
Requires
- php: >=5.4.0
- ext-mongodb: >=1.0.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-12 17:47:54 UTC
README
MongoDateBehavior 行为自动将指定的属性填充为当前的 ISODate。
默认情况下,MongoDateBehavior 行为会在关联的 AR 对象被插入时填充 created
和 updated
属性为当前的 ISODate;当 AR 对象被更新时,它将填充 updated
属性为 ISODate。
安装
安装此扩展的首选方法是使用 composer。
运行以下命令之一:
php composer.phar require --prefer-dist mongosoft/yii2-mongodate-behavior "*"
或添加以下内容到您的 composer.json
文件的 require
部分:
"mongosoft/yii2-mongodate-behavior": "*"
to the require
section of your composer.json
file.
使用方法
上传文件
在您的模型中附加行为
class User extends ActiveRecord { /** * @inheritdoc */ public static function collectionName() { return 'user'; } /** * @inheritdoc */ public function attributes() { return [ '_id', 'name', 'created', 'updated', ]; } /** * @inheritdoc */ function behaviors() { return [ MongoDateBehavior::className(), ]; } }