本文整理汇总了PHP中yii\behaviors\TimestampBehavior::className方法的典型用法代码示例。如果您正苦于以下问题:PHP TimestampBehavior::className方法的具体用法?PHP TimestampBehavior::className怎么用?PHP TimestampBehavior::className使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\behaviors\TimestampBehavior
的用法示例。
在下文中一共展示了TimestampBehavior::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return ['timestamp' => ['class' => AttributeBehavior::className(), 'value' => function ($event) {
return $this->module->enableConfirmation ? 0 : 1;
}, 'attributes' => [self::EVENT_INIT_REGISTER => 'status']], ['class' => TimestampBehavior::className(), 'attributes' => [self::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], self::EVENT_UPDATE => ['updated_at']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => ['created_at']], 'value' => function ($event) {
$model = $event->sender;
return Yii::$app->formatter->asDatetime($model->created_at, 'php:l, j F Y г., H:i:s');
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_VALIDATE => ['created_at']], 'value' => function ($event) {
/* @var $model \users\models\Users */
$model = $event->sender;
$model->created_at = $model->getOldAttribute('created_at');
return $model->created_at;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => ['updated_at']], 'value' => function ($event) {
$model = $event->sender;
return Yii::$app->formatter->asDatetime($model->updated_at, 'php:l, j F Y г., H:i:s');
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_VALIDATE => ['updated_at']], 'value' => function ($event) {
/* @var $model \users\models\Users */
$model = $event->sender;
$model->updated_at = $model->getOldAttribute('updated_at');
return $model->updated_at;
}], ['class' => AttributeBehavior::className(), 'attributes' => [self::EVENT_LOGIN => ['auth_key']], 'value' => function ($event) {
/* @var $model \users\models\Users */
$model = $event->sender;
if (!$model->auth_key && !$model->isNewRecord) {
$model->updateAuthKey();
}
return $model->auth_key;
}]];
}
示例2: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return ['added_on' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'added_on', 'updatedAtAttribute' => false, 'value' => function () {
$date = new \DateTime();
return $date->format('Y:m:d H:i:s');
}]];
}
示例3: behaviors
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'value' => function ($event) {
$user = Yii::$app->get('user', false);
return $user && !$user->isGuest ? $user->identity->username : null;
}]];
}
示例4: behaviors
public function behaviors()
{
$result = parent::behaviors();
return array_merge($result, ['timestamp' => ['class' => \yii\behaviors\TimestampBehavior::className(), 'attributes' => [\yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => 'date_update'], 'value' => function () {
return date('Y-m-d H:i:s');
}]]);
}
示例5: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'creation_time', ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time'], 'value' => function () {
return date('U');
/*unix timestamp */
}]];
}
示例6: behaviors
public function behaviors()
{
$behaviors = ['attributesMapBehavior' => ['class' => '\\yiicod\\mailqueue\\models\\behaviors\\AttributesMapBehavior', 'attributesMap' => Yii::$app->get('mailqueue')->modelMap['MailQueue']], 'timestampBehavior' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => in_array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldCreateDate'], $this->attributes()) ? Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldCreateDate'] : null, 'updatedAtAttribute' => in_array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldUpdateDate'], $this->attributes()) ? Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldUpdateDate'] : null, 'value' => function () {
return date("Y-m-d H:i:s");
}], 'XssBehavior' => ['class' => '\\yiicod\\base\\models\\behaviors\\XssBehavior', 'attributesExclude' => array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldBody'])]];
return ArrayHelper::merge(parent::behaviors(), $behaviors);
}
示例7: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'], 'value' => function () {
return date('Y-m-d H:i:s');
/* mysql datetime format is ‘AAAA-MM-JJ HH:MM:SS’*/
}]];
}
示例8: behaviors
public function behaviors()
{
return ['autotime' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_date', 'updatedAtAttribute' => 'updated_date', 'value' => function () {
// return \Yii::$app->formatter->asDatetime('now','php:Y-m-d H:i:s'); BUGGED!!! doesnt change timezone on Travis. no clue why
return (new \DateTime())->format('Y-m-d H:i:s');
}]];
}
示例9: behaviors
public function behaviors()
{
/*Sources:
* https://yii2framework.wordpress.com/2014/11/15/yii-2-behaviors-blameable-and-timestamp/comment-page-1/
* https://toster.ru/q/82962
* */
// If table not have fields, then behavior not use
$behaviors = [];
//Check timestamp
if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) {
$behaviors['timestamp'] = ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdAtAttribute, $this->updatedAtAttribute], ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedAtAttribute]];
}
//Check blameable
if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) {
$behaviors['blameable'] = ['class' => UserDataBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdByAttribute, $this->updatedByAttribute], ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedByAttribute]];
}
//Check trash
if ($this->hasAttribute($this->removedAttribute)) {
$behaviors['trash'] = ['class' => TrashBehavior::className(), 'trashAttribute' => $this->removedAttribute];
}
//Check locked
if ($this->hasAttribute($this->lockedAttribute)) {
$behaviors['locked'] = ['class' => LockedBehavior::className(), 'lockedAttribute' => $this->lockedAttribute];
}
if ($this->isNestedSet()) {
$behaviors['tree'] = ArrayHelper::merge(['class' => \creocoder\nestedsets\NestedSetsBehavior::className(), 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth'], $this->hasAttribute('tree') ? ['treeAttribute' => 'tree'] : []);
}
return $behaviors;
}
示例10: behaviors
public function behaviors()
{
return ['date' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'date', ActiveRecord::EVENT_BEFORE_UPDATE => 'date'], 'value' => function () {
return empty($this->date) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', strtotime($this->date));
}], 'dateGMT' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'date_gmt', ActiveRecord::EVENT_BEFORE_UPDATE => 'date_gmt'], 'value' => function () {
return empty($this->date) ? gmdate('Y-m-d H:i:s') : gmdate('Y-m-d H:i:s', strtotime($this->date));
}]];
}
示例11: behaviors
/**
* @return array
*/
public function behaviors()
{
$data = [];
if ($this->isTimestampBehavior()) {
$data['timestamp'] = ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'created_at', ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'], 'value' => new Expression('NOW()')];
}
return $data;
}
示例12: behaviors
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['cnf_created']], 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['cnf_flags']], 'value' => function ($event) {
/** @var Conference $model */
$model = $event->sender;
return empty($model->cnf_flags) ? self::CONF_FLAG_DEFAULT : $model->cnf_flags;
}]];
}
示例13: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'alias'], 'value' => function ($event) {
return Inflector::slug($event->sender->title);
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'body'], 'value' => function ($event) {
return HtmlPurifier::process(Markdown::process($event->sender->content, 'gfm'));
}]];
}
示例14: behaviors
public function behaviors()
{
return [['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['route']], 'value' => function ($event) {
return Yii::$app->requestedRoute;
}], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['ip']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserIP();
}], ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['datetime']]]];
}
示例15: behaviors
public function behaviors()
{
return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at', ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at']], 'value' => function () {
return date('U');
}], 'username' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id'], 'value' => function () {
return \yii::$app->user->id;
}]];
}