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


PHP behaviors\AttributeBehavior類代碼示例

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


在下文中一共展示了AttributeBehavior類的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 [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'created_ip'], 'value' => function ($event) {
         return ip2long(Yii::$app->request->getUserIP());
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'created_ip'], 'value' => function ($event) {
         return long2ip($event->sender->created_ip);
     }], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id']]];
 }
開發者ID:faninv,項目名稱:gtqa,代碼行數:11,代碼來源:Favorite.php

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

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

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

示例6: behaviors

 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'member_id'], 'value' => function ($event) {
         return Yii::$app->user->identity->id;
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'real_amount'], 'value' => function ($event) {
         return $this->amount - $this->fee;
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'status'], 'value' => function ($event) {
         return 1;
     }]];
 }
開發者ID:cindyming,項目名稱:yii-advance,代碼行數:10,代碼來源:Cash.php

示例7: behaviors

 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at'], ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'user_id', 'updatedByAttribute' => 'user_id'], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'theMust'], 'value' => function ($event) {
         return $this->kpi->the_must;
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'theBest'], 'value' => function ($event) {
         return $this->kpi->the_best;
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'groupName'], 'value' => function ($event) {
         return $this->kpi->group->name;
     }]];
 }
開發者ID:phisithos,項目名稱:yii2-workshop-co-sapce,代碼行數:10,代碼來源:EvauateScore.php

示例8: behaviors

 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_ip']], 'value' => function ($event) {
         return Yii::$app->getRequest()->getUserIP();
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_host']], 'value' => function ($event) {
         return Yii::$app->getRequest()->getUserHost();
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_agent']], 'value' => function ($event) {
         return Yii::$app->getRequest()->getUserAgent();
     }]];
 }
開發者ID:statsandresults,項目名稱:statsandresults,代碼行數:13,代碼來源:Contact.php

示例9: behaviors

 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'member_id'], 'value' => function ($event) {
         if ($this->member_id) {
             return $this->member_id;
         } else {
             return Yii::$app->user->id;
         }
     }]];
 }
開發者ID:cindyming,項目名稱:yii-advance,代碼行數:10,代碼來源:InRecord.php

示例10: behaviors

 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'status'], 'value' => function ($event) {
         $dw = date("w", strtotime($this->date));
         if (in_array($dw, array(0, 6))) {
             return 1;
         } else {
             return 0;
         }
     }]];
 }
開發者ID:cindyming,項目名稱:yii-advance,代碼行數:11,代碼來源:Date.php

示例11: behaviors

 public function behaviors()
 {
     // if user is not an admin get the organizer id of the user account
     // admin users can and must set the organizer_id from a dropdown.
     if (!\Yii::$app->user->isAdmin()) {
         return array_merge(parent::behaviors(), [['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'organizer_id'], 'value' => function ($event) {
             return Yii::$app->user->identity->getOrganizer()->one()->getPrimaryKey();
         }]]);
     } else {
         return array_merge(parent::behaviors(), []);
     }
 }
開發者ID:EuresTools,項目名稱:eVote-web,代碼行數:12,代碼來源:Poll.php

示例12: behaviors

 public function behaviors()
 {
     return [['class' => AttributeBehavior::className(), 'attributes' => [self::EVENT_BEFORE_INSERT => [null], self::EVENT_BEFORE_UPDATE => [null]], 'value' => function ($event) {
         /* @var User $model */
         $model = $event->sender;
         $model->setting = Json::encode($this->settingBuild());
     }], ['class' => AttributeBehavior::className(), 'attributes' => [self::EVENT_AFTER_FIND => [null]], 'value' => function ($event) {
         /* @var User $model */
         $model = $event->sender;
         $model->setAttributes($model->settingParse());
     }]];
 }
開發者ID:Choate,項目名稱:vsftpd,代碼行數:12,代碼來源:User.php

示例13: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->attributes)) {
         $this->attributes = [BaseActiveRecord::EVENT_AFTER_VALIDATE => [$this->attribute], BaseActiveRecord::EVENT_AFTER_FIND => [$this->attribute]];
     }
 }
開發者ID:vaseninm,項目名稱:yii2-hstore,代碼行數:10,代碼來源:HstoreBehavior.php

示例14: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (empty($this->attributes)) {
         $this->attributes = [BaseActiveRecord::EVENT_BEFORE_INSERT => 'date', BaseActiveRecord::EVENT_BEFORE_UPDATE => 'date', BaseActiveRecord::EVENT_AFTER_FIND => 'date'];
     }
 }
開發者ID:radiata-cms,項目名稱:radiata,代碼行數:10,代碼來源:DateTimeBehavior.php

示例15: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->attribute !== null) {
         $this->attributes[BaseActiveRecord::EVENT_BEFORE_INSERT][] = $this->attribute;
     }
     parent::init();
 }
開發者ID:mdmsoft,項目名稱:yii2-autonumber,代碼行數:10,代碼來源:Behavior.php


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