mongosoft/yii2-mongodate-behavior

MongoDate 行为扩展适用于 Yii 2

安装次数: 106,412

依赖关系: 2

建议者: 0

安全: 0

星星: 6

关注者: 2

分支: 1

类型:yii2-extension

0.2.0 2016-07-08 13:21 UTC

This package is auto-updated.

Last update: 2024-09-12 17:47:54 UTC


README

MongoDateBehavior 行为自动将指定的属性填充为当前的 ISODate。

默认情况下,MongoDateBehavior 行为会在关联的 AR 对象被插入时填充 createdupdated 属性为当前的 ISODate;当 AR 对象被更新时,它将填充 updated 属性为 ISODate。

Latest Stable Version Total Downloads

安装

安装此扩展的首选方法是使用 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(),
        ];
    }
}