PHP code example of nox-it / yii2-nox-behaviors
1. Go to this page and download the library: Download nox-it/yii2-nox-behaviors library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nox-it / yii2-nox-behaviors example snippets
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
}