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


PHP AttributeBehavior::className方法代码示例

本文整理汇总了PHP中yii\behaviors\AttributeBehavior::className方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeBehavior::className方法的具体用法?PHP AttributeBehavior::className怎么用?PHP AttributeBehavior::className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\behaviors\AttributeBehavior的用法示例。


在下文中一共展示了AttributeBehavior::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 [['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

 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

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

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

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

 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

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

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

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

示例13: behaviors

 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'auth_key'], 'value' => function ($event) {
         return sha1(rand());
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'finance_fund'], 'value' => function ($event) {
         return $this->investment;
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'access_token'], 'value' => function ($event) {
         return sha1(rand());
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'password_hash'], 'value' => function ($event) {
         return Yii::$app->security->generatePasswordHash($this->password);
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'password_hash2'], 'value' => function ($event) {
         return Yii::$app->security->generatePasswordHash($this->password2);
     }]];
 }
开发者ID:cindyming,项目名称:yii-advance,代码行数:14,代码来源:Member.php

示例14: behaviors

 public function behaviors()
 {
     return ['modified' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'modified', ActiveRecord::EVENT_BEFORE_UPDATE => 'modified'], 'value' => function () {
         return date('Y-m-d H:i:s');
     }], 'modifiedGMT' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'modified_gmt', ActiveRecord::EVENT_BEFORE_UPDATE => 'modified_gmt'], 'value' => function () {
         return gmdate('Y-m-d H:i:s');
     }], '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));
     }], 'slug' => ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'slug', ActiveRecord::EVENT_BEFORE_UPDATE => 'slug'], 'value' => function () {
         return empty($this->slug) ? $this->genSlug($this->title) : $this->genSlug($this->slug);
     }]];
 }
开发者ID:linchpinstudios,项目名称:yii2-blog,代码行数:14,代码来源:BlogPosts.php

示例15: behaviors

 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'status'], 'value' => function ($event) {
         if ($this->status) {
             return $this->status;
         } else {
             return 0;
         }
     }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'charge'], 'value' => function ($event) {
         if ($this->type) {
             return round($this->total_price * System::loadConfig('sell_fee_rate'), 2);
         } else {
             return 0;
         }
     }]];
 }
开发者ID:cindyming,项目名称:yii-advance,代码行数:16,代码来源:StackTransaction.php


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