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


PHP ActiveRecord::save方法代码示例

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


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

示例1: save

 /**
  * Saves the current model
  * @param boolean $runValidation whether to perform validation before saving the record.
  * If the validation fails, the record will not be saved to database.
  * @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param boolean $withSubtree whether subtree sticks to model (e.g. if model parent is changes - should subtree follow model or stay with model's parent)
  * @return boolean whether the saving succeeds
  */
 public function save($runValidation = true, $attributeNames = null, $withSubtree = true)
 {
     $transaction = $this->getDb()->beginTransaction();
     try {
         $result = false;
         if ($this->isNewRecord) {
             $this->setNodeLevel($this->calculateLevel());
             if (parent::save($runValidation, $attributeNames)) {
                 $this->setAncestorsLinks();
                 $result = true;
             }
         } else {
             if ($this->{$this->getIdParentAttribute()} != $this->getOldParentId() && $this->prepareParentChange($withSubtree) && parent::save($runValidation, $attributeNames)) {
                 $result = true;
             }
         }
         if ($result === true) {
             $transaction->commit();
             return true;
         } else {
             $transaction->rollBack();
             return false;
         }
     } catch (Exception $e) {
         $transaction->rollBack();
         throw $e;
     }
 }
开发者ID:codiverum,项目名称:yii2-abstracttree,代码行数:37,代码来源:AbstractNode.php

示例2: performModelSave

 /**
  * @param ActiveRecord $model
  * @param array $params
  * @return bool|mixed
  */
 public function performModelSave(ActiveRecord $model, array $params)
 {
     $ajax = Yii::$app->request->isAjax;
     if ($model->save()) {
         if ($ajax) {
             $data = ['success' => true, 'message' => Yii::t('management', 'Model saved')];
             if (isset($params['success']) && is_callable($params['success'])) {
                 $data = array_merge($data, call_user_func($params['success'], $model));
             }
             return $this->sendJson($data);
         }
         if (isset($params['fallback']) && is_callable($params['fallback'])) {
             return call_user_func($params['fallback'], $model);
         }
     } else {
         if ($ajax) {
             $data = ['success' => false, 'message' => Yii::t('management', 'Model not saved'), 'messages' => ActiveForm::validate($model)];
             if (isset($params['error']) && is_callable($params['error'])) {
                 $data = array_merge($data, call_user_func($params['error'], $model));
             }
             return $this->sendJson($data);
         }
     }
     return false;
 }
开发者ID:hauntd,项目名称:help-center,代码行数:30,代码来源:ManagementController.php

示例3: save

 /**
  * @param boolean $runValidation
  * @throws RowException
  */
 public function save($runValidation = true)
 {
     if ($runValidation) {
         $this->validate();
     }
     $this->_instance->save(false);
 }
开发者ID:Bladefidz,项目名称:ocfa_yii,代码行数:11,代码来源:Model.php

示例4: save

 public function save($runValidation = true, $attributeNames = NULL)
 {
     $this->user_id = Yii::$app->getUser()->id;
     $this->created_at = time();
     //$this->content = strip_tags($this->content); //去掉html标签
     parent::save($runValidation, $attributeNames);
 }
开发者ID:abwxwx,项目名称:yiistudy,代码行数:7,代码来源:Comment.php

示例5: save

 public function save($runValidation = true, $attributeNames = null)
 {
     if ($this->tmpname != null) {
         rename("{$this->tempPath}/{$this->tmpname}", "{$this->basePath}/{$this->tmpname}");
         $this->path = $this->tmpname;
     }
     return parent::save($runValidation, $attributeNames);
 }
开发者ID:blackvalmiki,项目名称:billboard-reservation,代码行数:8,代码来源:Foto.php

示例6: createRecord

 /**
  * @param \yii\base\ModelEvent $event
  * @throws Exception
  */
 public function createRecord($event)
 {
     foreach ($this->attributes as $key => $value) {
         if (is_string($value)) {
             $this->target->{$key} = ArrayHelper::getValue($event->sender, $value);
         } else {
             if (CheckHelper::isCallable($value)) {
                 $this->target->{$key} = call_user_func($value, $event->sender);
             } else {
                 throw new Exception();
             }
         }
     }
     if (!$this->target->save()) {
         throw new Exception('Save target error: ' . Json::encode($this->target));
     }
 }
开发者ID:shuangjie,项目名称:galaxy,代码行数:21,代码来源:RecordBehavior.php

示例7: save

 public function save($runValidation = true, $attributeNames = null)
 {
     $result = parent::save($runValidation, $attributeNames);
     if ($result) {
         // При изменении препаратов, менять пользователя и дату изменения в карте глаукомного пациента
         Glaukuchet::findOne($this->id_glaukuchet)->UpdateChangeAttributes();
     }
     return $result;
 }
开发者ID:vovancho,项目名称:yii2test,代码行数:9,代码来源:Glprep.php

示例8: save

 /**
  * @param bool $runValidation
  * @param null $attributeNames
  *
  * @return bool|void
  */
 public function save($runValidation = true, $attributeNames = null)
 {
     if ($this->getIsNewRecord()) {
         $this->date_create = date('Y-m-d H:i:s');
     }
     if (is_null($this->date_execute)) {
         $this->date_execute = date('Y-m-d H:i:s');
     }
     return parent::save($runValidation, $attributeNames);
 }
开发者ID:salatnik,项目名称:yii2-backop,代码行数:16,代码来源:OperationRecord.php

示例9: save

 public function save($runValidation = true, $attributeNames = null)
 {
     if (!$this->history) {
         $this->history = [];
     }
     $oldUrl = $this->getOldAttribute('url');
     if ($this->url !== $oldUrl) {
         $this->history += [$oldUrl];
     }
     return parent::save($runValidation, $attributeNames);
 }
开发者ID:serhiobb,项目名称:RGK-test,代码行数:11,代码来源:Url.php

示例10: save

 public function save($runValidation = true, $attributeNames = null)
 {
     if (parent::save($runValidation, $attributeNames)) {
         //dopo aver salvato le modifiche, processa gli upload delle foto
         foreach ($this->addimage as $tmpfoto) {
             $foto = new Foto();
             $foto->cartellone = $this->id;
             $foto->tmpname = $tmpfoto;
             $foto->save();
         }
         return true;
     }
     return false;
 }
开发者ID:blackvalmiki,项目名称:billboard-reservation,代码行数:14,代码来源:Cartellone.php

示例11: processModel

 /**
  * @param ActiveRecord $model
  */
 private function processModel(ActiveRecord $model)
 {
     $model->detachBehaviors();
     $count = $model->{$this->countRelation}();
     if ($count instanceof ActiveQuery) {
         $count = $count->count();
     } else {
         if (is_array($count)) {
             $count = json_encode($count);
         }
     }
     $model->{$this->columnToUpdate} = $count;
     $model->save(false, [$this->columnToUpdate]);
 }
开发者ID:idealia,项目名称:yii2-children-count-behavior,代码行数:17,代码来源:ChildrenCountBehavior.php

示例12: save

 public function save($runValidation = true, $attributeNames = NULL)
 {
     self::formatModel();
     $new_assigned = '';
     $send_notification = 0;
     if ($this->assigned == '1') {
         $new_assigned = \app\memoboard\functions::getArray($this->assigned_to);
         $send_notification = $this->send_notification;
     }
     $connection = \Yii::$app->db;
     $transaction = $connection->beginTransaction();
     if (parent::save() && self::saveAssign($new_assigned, $send_notification)) {
         $transaction->commit();
         return true;
     }
     $transaction->rollback();
     return false;
 }
开发者ID:afernandes465,项目名称:memoboard,代码行数:18,代码来源:Task.php

示例13: save

 public function save($runValidation = true, $attributeNames = null)
 {
     $uploadedFile = UploadedFile::getInstance($this, 'preview');
     if ($uploadedFile) {
         $filePath = 'uploads/' . $uploadedFile->baseName . '.' . $uploadedFile->extension;
         if (file_exists($filePath)) {
             $filePath = 'uploads/' . $uploadedFile->baseName . 'N.' . $uploadedFile->extension;
         }
         $uploadedFile->saveAs($filePath);
         $this->preview = '/' . $filePath;
     } else {
         $oldPreview = $this->getOldAttribute('preview');
         if ($oldPreview) {
             $this->preview = $oldPreview;
         }
     }
     return parent::save($runValidation, $attributeNames);
 }
开发者ID:serhiobb,项目名称:RGK-test,代码行数:18,代码来源:Book.php

示例14: insertTo

 /**
  * @param $position
  * @return bool
  * @throws \yii\db\Exception
  */
 public function insertTo($position)
 {
     if ($this->getValue() == $position) {
         return true;
     }
     // 59 -> 56 = 58 57 56
     // 56 -> 59 = 57 58 59
     $start = $this->getValue();
     $end = $position;
     if ($start == null || $start == 0) {
         $this->setInsertSort();
         $this->owner->save();
         return true;
     }
     $direction = $start > $end ? static::DirectionDown : static::DirectionUp;
     $query = $this->getQuery();
     $query->andWhere(['between', $this->attributeName, min($start, $end), max($start, $end)]);
     $query->getSortBehavior()->sort();
     /**
      * @var ISortableActiveRecord[]|ActiveRecord[] $items
      */
     $items = $query->all();
     $transaction = $this->owner->getDb()->beginTransaction();
     try {
         foreach ($items as $index => $item) {
             if ($item->getPrimaryKey() == $this->owner->getPrimaryKey()) {
                 $item->getSortBehavior()->setSort($position);
                 $item->save();
             } else {
                 $item->getSortBehavior()->setSort($item->getSortBehavior()->getValue() + ($direction == static::DirectionDown ? 1 : -1));
                 $item->save();
             }
         }
         /* @TODO сделать фикс позиций, что бы не перескакивало и не было дублей */
         $transaction->commit();
     } catch (\Exception $ex) {
         $transaction->rollBack();
         return false;
     }
     return true;
 }
开发者ID:nanodesu88,项目名称:yii2-activerecord-sort,代码行数:46,代码来源:SortBehavior.php

示例15: storeDataRecord

 /**
  * Store data record and track change statistics
  *
  * @param ActiveRecord $ActiveRecord
  *
  * @return bool false if not saved
  */
 protected function storeDataRecord(ActiveRecord $ActiveRecord)
 {
     if ($ActiveRecord->getDirtyAttributes()) {
         $unsaved_record = clone $ActiveRecord;
         // Save record
         if (!$ActiveRecord->save()) {
             // Create error message
             $message = "Save error: " . json_encode($ActiveRecord->errors) . "\n";
             $message .= "Record data: " . json_encode($ActiveRecord->getAttributes()) . "\n";
             trigger_error($message, E_USER_WARNING);
             $this->incStat('error_' . $ActiveRecord->tableName());
             return false;
         }
         // Store statistics
         if ($unsaved_record->isNewRecord) {
             $this->incStat('new_' . $ActiveRecord->tableName());
         } else {
             $this->incStat('update_' . $ActiveRecord->tableName());
         }
     }
     return true;
 }
开发者ID:drsdre,项目名称:yii2-betssonsports,代码行数:29,代码来源:Cache.php


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