当前位置: 首页>>代码示例>>PHP>>正文


PHP TimestampBehavior::className方法代码示例

本文整理汇总了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;
     }]];
 }
开发者ID:fourteenmeister,项目名称:yii2-app-advanced,代码行数:32,代码来源:Users.php

示例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');
     }]];
 }
开发者ID:zxvad,项目名称:PriceCalculationOfCircuitBoards,代码行数:10,代码来源:InputParams.php

示例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;
     }]];
 }
开发者ID:joorloohuis,项目名称:bat-web-frontend,代码行数:7,代码来源:Upload.php

示例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');
     }]]);
 }
开发者ID:evgenylev,项目名称:books,代码行数:7,代码来源:Books.php

示例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 */
     }]];
 }
开发者ID:J-Beam,项目名称:SchoolDMS,代码行数:10,代码来源:Admin.php

示例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);
 }
开发者ID:yiicod,项目名称:yii2-mailqueue,代码行数:7,代码来源:MailQueueModel.php

示例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’*/
     }]];
 }
开发者ID:kleitz,项目名称:golfleague,代码行数:10,代码来源:User.php

示例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');
     }]];
 }
开发者ID:yurii-github,项目名称:yii2-mylib,代码行数:7,代码来源:Books.php

示例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;
 }
开发者ID:sibds,项目名称:yii2-activerecord,代码行数:29,代码来源:ActiveRecord.php

示例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));
     }]];
 }
开发者ID:linchpinstudios,项目名称:yii2-blog,代码行数:8,代码来源:BlogComments.php

示例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;
 }
开发者ID:Zhanat87,项目名称:alina.test,代码行数:11,代码来源:ActiveRecord.php

示例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;
     }]];
 }
开发者ID:mosedu,项目名称:confprof,代码行数:8,代码来源:Conference.php

示例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'));
     }]];
 }
开发者ID:faninv,项目名称:gtqa,代码行数:11,代码来源:Question.php

示例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']]]];
 }
开发者ID:pythagor,项目名称:yii2-mongolog,代码行数:8,代码来源:Log.php

示例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;
     }]];
 }
开发者ID:developer-av,项目名称:yii2-blog,代码行数:8,代码来源:Posts.php


注:本文中的yii\behaviors\TimestampBehavior::className方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。