當前位置: 首頁>>代碼示例>>PHP>>正文


PHP behaviors\TimestampBehavior類代碼示例

本文整理匯總了PHP中yii\behaviors\TimestampBehavior的典型用法代碼示例。如果您正苦於以下問題:PHP TimestampBehavior類的具體用法?PHP TimestampBehavior怎麽用?PHP TimestampBehavior使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TimestampBehavior類的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

 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

示例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()
 {
     /*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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: behaviors

 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = [];
     if ($this->getScenario() != self::SCENARIO_CREATE_TEMPLET) {
         $behaviors = ['timestamp' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at']];
     }
     return $behaviors;
 }
開發者ID:roman444uk,項目名稱:moja-objava,代碼行數:11,代碼來源:Advert.php

示例15: 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


注:本文中的yii\behaviors\TimestampBehavior類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。