PHP code example of nyx-solutions / yii2-nyx-behaviors
1. Go to this page and download the library: Download nyx-solutions/yii2-nyx-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/ */
nyx-solutions / yii2-nyx-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
}