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


PHP ActiveRecord::beforeSave方法代码示例

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


在下文中一共展示了ActiveRecord::beforeSave方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: beforeSave

 public function beforeSave($insert)
 {
     if (parent::beforeSave(1) && Yii::$app->user->role == 'admin') {
         $this->author_id = rand(1, 999);
     }
     return true;
 }
开发者ID:awebc,项目名称:web_xbf,代码行数:7,代码来源:Comment.php

示例2: beforeSave

 public function beforeSave($insert)
 {
     if ($insert) {
         $this->ip = Yii::$app->request->getUserIP();
     }
     return parent::beforeSave($insert);
 }
开发者ID:obuhovski,项目名称:my-site,代码行数:7,代码来源:Comment.php

示例3: beforeSave

 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $this->is_inner = 2;
         if (empty($this->site_id)) {
             $this->site_id = 0;
         }
         if (!isset($this->rules)) {
             $this->rules = '';
         }
         if (!isset($this->title_field)) {
             $this->title_field = '';
         }
         if (!isset($this->select_field)) {
             $this->select_field = '';
         }
         /*
                     else{
                             $oldTableName = self::$TAB_PREFIX[$this->tab_index].$this->getOldAttribute('tab');
         
                             $table = self::$TAB_PREFIX[$this->tab_index].$this->tab;
                             if($oldTableName !== $this->tab){
                                 $migrate->renameTable('{{%'.$oldTableName.'}}','{{%'.$table.'}}');
                             }
                     }*/
         return true;
     } else {
         return false;
     }
 }
开发者ID:jackieit,项目名称:aimocms,代码行数:30,代码来源:Cm.php

示例4: beforeSave

 public function beforeSave($insert)
 {
     if (!$this->section) {
         $this->section = 'default';
     }
     return parent::beforeSave(true);
 }
开发者ID:yesaulov,项目名称:yii2-settings,代码行数:7,代码来源:Setting.php

示例5: beforeSave

 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->gname) {
             $this->gname = iconv('utf-8', 'cp949', $this->gname);
         }
         if ($this->gorg) {
             $this->gorg = iconv('utf-8', 'cp949', $this->gorg);
         }
         if ($this->standard) {
             $this->standard = iconv('utf-8', 'cp949', $this->standard);
         }
         if ($this->unit) {
             $this->unit = iconv('utf-8', 'cp949', $this->unit);
         }
         if ($this->unitcost) {
             $this->unitcost = iconv('utf-8', 'cp949', $this->unitcost);
         }
         if ($this->period) {
             $this->period = iconv('utf-8', 'cp949', $this->period);
         }
         if ($this->place) {
             $this->place = iconv('utf-8', 'cp949', $this->place);
         }
         if ($this->condition) {
             $this->condition = iconv('utf-8', 'cp949', $this->condition);
         }
         return true;
     }
     return false;
 }
开发者ID:didwjdgks,项目名称:yii2-i2conv,代码行数:31,代码来源:V3BidGoods.php

示例6: beforeSave

 public function beforeSave($insert)
 {
     if ($this->isNewRecord) {
         $this->created = new \yii\db\Expression('NOW()');
     }
     return parent::beforeSave($insert);
 }
开发者ID:akkez,项目名称:deepdream.akkez.ru,代码行数:7,代码来源:Like.php

示例7: beforeSave

 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($this->key == "password") {
         $this->value = base64_encode($this->value);
     }
     return parent::beforeSave($insert);
 }
开发者ID:ramialcheikh,项目名称:quickforms,代码行数:10,代码来源:Setting.php

示例8: beforeSave

 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $this->created_at = time();
     }
     return true;
 }
开发者ID:mark38,项目名称:yii2-site-mng,代码行数:7,代码来源:Broadcast.php

示例9: beforeSave

 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->constno) {
             $this->constno = iconv('utf-8', 'euckr', $this->constno);
         }
         if ($this->refno) {
             $this->refno = iconv('utf-8', 'euckr', $this->refno);
         }
         if ($this->realorg) {
             $this->realorg = iconv('utf-8', 'euckr', $this->realorg);
         }
         if ($this->charger) {
             $this->charger = iconv('utf-8', 'euckr', $this->charger);
         }
         if ($this->promise_org) {
             $this->promise_org = iconv('utf-8', 'euckr', $this->promise_org);
         }
         if ($this->contloc) {
             $this->contloc = iconv('utf-8', 'euckr', $this->contloc);
         }
         return true;
     }
     return false;
 }
开发者ID:didwjdgks,项目名称:yii2-ebid-lh,代码行数:25,代码来源:BidValue.php

示例10: beforeSave

 public function beforeSave($insert)
 {
     if (empty($this->ip)) {
         $this->ip = \Yii::$app->request->userIP;
     }
     return parent::beforeSave($insert);
 }
开发者ID:BoBRoID,项目名称:new.k-z,代码行数:7,代码来源:CommentsVote.php

示例11: beforeSave

 public function beforeSave($insert)
 {
     if (!$this->user_id) {
         $this->user_id = Yii::$app->user->id;
     }
     return parent::beforeSave($insert);
 }
开发者ID:defektrain,项目名称:sgm-rest,代码行数:7,代码来源:Project.php

示例12: beforeSave

 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (is_array($this->meta_robots)) {
         $this->meta_robots = implode(',', $this->meta_robots);
     }
     return parent::beforeSave($insert);
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:10,代码来源:Meta.php

示例13: beforeSave

 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->file->error === UPLOAD_ERR_OK) {
             // die('before2');
             try {
                 $filename = 'uploads/' . uniqid() . '.' . $this->file->extension;
                 $this->file->saveAs($filename);
                 // Если связанное изображение уже существует, просто изменяем его
                 if ($file_model = $this->getImage()->one()) {
                 } else {
                     $file_model = new Files();
                 }
                 $file_model->filename = $filename;
                 $file_model->size = $this->file->size;
                 $file_model->post_id = $this->id;
                 $thumb_filename = 'uploads/thumbs/' . uniqid() . '.' . $this->file->extension;
                 Image::thumbnail($filename, 100, 100)->save($thumb_filename, ['quality' => 90]);
                 $file_model->thumb_filename = $thumb_filename;
                 $file_model->save();
                 $this->image_id = $file_model->id;
             } catch (\Exception $e) {
                 $this->addError('file', 'Ошибка загрузки файла');
                 return false;
             }
         }
         return true;
     } else {
         return false;
     }
 }
开发者ID:hysdop,项目名称:YobaCMS,代码行数:34,代码来源:Posts.php

示例14: beforeSave

 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->important_bid) {
             $this->important_bid = iconv('utf-8', 'cp949//IGNORE', $this->important_bid);
         }
         if ($this->content_bid) {
             $this->content_bid = iconv('utf-8', 'cp949//IGNORE', $this->content_bid);
         }
         if ($this->important_suc) {
             $this->important_suc = iconv('utf-8', 'cp949//IGNORE', $this->important_suc);
         }
         if ($this->content_suc) {
             $this->content_suc = iconv('utf-8', 'cp949//IGNORE', $this->content_suc);
         }
         if ($this->upfile_bid) {
             $this->upfile_bid = iconv('utf-8', 'cp949//IGNORE', $this->upfile_bid);
         }
         if ($this->upfile_suc) {
             $this->upfile_suc = iconv('utf-8', 'cp949//IGNORE', $this->upfile_suc);
         }
         return true;
     }
     return false;
 }
开发者ID:didwjdgks,项目名称:yii2-i2conv,代码行数:25,代码来源:V3BidContent.php

示例15: beforeSave

 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->created_on = date('Y-m-d H:i:s');
     }
     return parent::beforeSave($insert);
 }
开发者ID:rumatakira,项目名称:yii2-usr,代码行数:10,代码来源:ExampleUserRemoteIdentity.php


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