nyx-solutions/yii2-nyx-behaviors
Composer 安装命令:
composer require nyx-solutions/yii2-nyx-behaviors
包简介
Yii2 nyx Behaviors
README 文档
README
Collection of useful behaviors for Yii Framework 2.0 (at the present there is only one behavior, the datetime behavior.).
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist nyx-solutions/yii2-nyx-behaviors "*"
or add
"nyx-solutions/yii2-nyx-behaviors": "*"
to the require section of your composer.json file.
Usage
In your base ActiveRecord Model you can add the following behaviors method:
namespace common\models; use \yii\helpers\ArrayHelper; /** * Class ActiveRecordModel * * @package common\models */ class ActiveRecordModel extends \yii\db\ActiveRecord { #region Behaviors /** * @inheritdoc */ public function behaviors() { $behaviors = []; if ($this->hasAttribute('createdAt') && $this->hasAttribute('updatedAt')) { $behaviors['datetime'] = [ 'class' => \nyx\behaviors\DateTimeBehavior::className(), 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['createdAt', 'updatedAt'], ActiveRecord::EVENT_BEFORE_UPDATE => 'updatedAt' ] ]; } return ArrayHelper::merge(parent::behaviors(), $behaviors); } #endregion }
License
yii2-nyx-behaviors is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-06-01