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


PHP CActiveRecord::save方法代码示例

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


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

示例1: update

 /**
  * @param CActiveRecord $model
  * @param $sortableAttribute
  * @param $sortOrderData
  *
  * @return string
  */
 private function update($model, $sortableAttribute, $sortOrderData)
 {
     $pk = $model->tableSchema->primaryKey;
     $pk_array = array();
     if (is_array($pk)) {
         // composite key
         $string_ids = array_keys($sortOrderData);
         $array_ids = array();
         foreach ($string_ids as $string_id) {
             $array_ids[] = explode(',', $string_id);
         }
         foreach ($array_ids as $array_id) {
             $pk_array[] = array_combine($pk, $array_id);
         }
     } else {
         // normal key
         $pk_array = array_keys($sortOrderData);
     }
     $models = $model->model()->findAllByPk($pk_array);
     $transaction = Yii::app()->db->beginTransaction();
     try {
         foreach ($models as $model) {
             $_key = is_array($pk) ? implode(',', array_values($model->primaryKey)) : $model->primaryKey;
             $model->{$sortableAttribute} = $sortOrderData[$_key];
             $model->save();
         }
         $transaction->commit();
     } catch (Exception $e) {
         // an exception is raised if a query fails
         $transaction->rollback();
     }
 }
开发者ID:zhaoyan158567,项目名称:YiiBooster,代码行数:39,代码来源:TbSortableAction.php

示例2: checkUpdatedAtField

 /**
  * @param CActiveRecord $record
  * @param string        $colName
  * @param string        $newValue
  */
 protected function checkUpdatedAtField(CActiveRecord $record, $colName = 'name', $newValue = 'xxxxx')
 {
     $oldColumnValue = $record->{$colName};
     // Modifier l'objet met le champ updated_at à jour
     $oldUpdatedAt = $record->updated_at;
     $record->{$colName} = $newValue;
     $this->assertTrue($record->save());
     $this->assertNotEquals($oldUpdatedAt, $record->updated_at);
     // restauration de la valeur de départ
     $record->{$colName} = $oldColumnValue;
     $this->assertTrue($record->save());
 }
开发者ID:ChristopheBrun,项目名称:hLib,代码行数:17,代码来源:DbTestCase.php

示例3: Save

 /**
  * Переопределенная функция сохранения группы LDAP.
  * Помимо сохранения данных группы LDAP, присваиваются выбранные права доступа
  * 
  * @param type $runValidation
  * @param type $attributes
  * @throws CHttpException
  */
 public function Save($runValidation = true, $attributes = null)
 {
     /* $selectedRows - массив выбранных ролей группы LDAP */
     $selectedRows = (string) filter_input(INPUT_POST, 'items') !== '' ? json_decode((string) filter_input(INPUT_POST, 'items'), true) : [];
     /* $_POST['oper'] может быть "edit" или "add", редактирование или добавление новой записи */
     if ((string) filter_input(INPUT_POST, 'oper') === '') {
         throw new CHttpException(500, 'Отсутствует POST переменная "oper"');
     }
     /* ИД группы LDAP, который редактируется, если необходим */
     $editid = (string) filter_input(INPUT_POST, 'editid');
     $oper = (string) filter_input(INPUT_POST, 'oper');
     if ($oper === 'edit' && $editid === '') {
         throw new CHttpException(500, 'Отсутствует POST переменная "editid"');
     }
     /* Сохраняем модель группы LDAP и присваиваем роли */
     if (parent::save($runValidation, $attributes) !== false) {
         /*  $auth = Yii::app()->authManager; */
         /* Удаляем все роли группы LDAP при сохранении изменений профиля групп LDAP */
         if ($editid !== '') {
             AuthAssignmentLdap::model()->deleteAll('groupid = :groupid', array(':groupid' => $editid));
         }
         /* Присваиваем выбранные роли группе LDAP */
         if ($editid === '' && $oper === 'add') {
             $editid = parent::getPrimaryKey();
         }
         if (count((array) $selectedRows) > 0) {
             foreach (array_keys($selectedRows) as $AuthItem) {
                 $model = new AuthAssignmentLdap();
                 $model->itemname = $AuthItem;
                 $model->groupid = $editid;
                 $model->save();
             }
         }
     }
 }
开发者ID:vovancho,项目名称:baseportal,代码行数:43,代码来源:Groupldap.php

示例4: assertSaves

 /**
  * Assert thet the model can be saved without error and, if errors are present, print
  * out the corresponding error messages.
  * @param CActiveRecord $model
  */
 public function assertSaves(CActiveRecord $model)
 {
     $saved = $model->save();
     if ($model->hasErrors()) {
         VERBOSE_MODE && print_r($model->getErrors());
     }
     $this->assertTrue($saved);
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:13,代码来源:X2TestCase.php

示例5: save

 public function save($runValidation = true, $attributes = null)
 {
     if (in_array($this->tableName(), array('{{post}}', '{{onlinehelp}}'))) {
         Yii::app()->user->setFlash('warning', '<strong>' . Yii::t('site', 'Info') . '</strong><br />' . Yii::t('site', 'Not allowed to save items in table {tableName} in this demo version.', array('{tableName}' => str_replace(array('{{', '}}'), array('', ''), $this->tableName()))));
         return true;
     }
     return parent::save($runValidation, $attributes);
 }
开发者ID:jordan095,项目名称:kpu-iadel,代码行数:8,代码来源:Model.php

示例6: saveActiveRecord

 public function saveActiveRecord(CActiveRecord $record)
 {
     try {
         if (!$record->save()) {
             new \Error(5, null, json_encode($record->getErrors()));
         }
     } catch (Exception $e) {
         new \Error(5, null, $e->getMesaage());
     }
 }
开发者ID:Yougmark,项目名称:TiCheck_Server,代码行数:10,代码来源:ModifyController.php

示例7: save

 public function save($runValidation = true, $attributes = null)
 {
     parent::save($runValidation, $attributes);
     if ($this->rank == null) {
         $this->rank = $this->id;
         $this->setIsNewRecord(false);
         $this->save(false);
     }
     return true;
 }
开发者ID:lidijakralj,项目名称:bober,代码行数:10,代码来源:GalleryPhoto.php

示例8: saveFromPost

 /**
  * Attempts to save the specified model with attribute values from POST. If 
  * the saving fails or if no POST data is available it returns false.
  * @param CActiveRecord $model the model
  * @return boolean whether the model was saved
  */
 protected function saveFromPost(&$model)
 {
     if (isset($_POST[$this->getModelClass()])) {
         $model->attributes = $_POST[$this->getModelClass()];
         if ($model->save()) {
             return true;
         }
     }
     return false;
 }
开发者ID:pweisenburger,项目名称:xbmc-video-server,代码行数:16,代码来源:ModelController.php

示例9: save

 public function save($runValidation = true, $attributes = NULL)
 {
     $status = parent::save($runValidation, $attributes);
     if (!$this->getIsInversed()) {
         $inversed = new Contact();
         $inversed->user_id = $this->contact_id;
         $inversed->contact_id = $this->user_id;
         $inversed->save(false);
     }
     return $status;
 }
开发者ID:jayrulez,项目名称:yiisns,代码行数:11,代码来源:Contact.php

示例10: save

 public function save($runValidation = true, $attributes = NULL)
 {
     $a = parent::save($runValidation, $attributes);
     if ($this->public && $this->hash == '') {
         $download = new Download();
         $download->file_id = $this->id;
         $download->company_id = Yii::app()->user->Company;
         $this->hash = $download->id = md5(mt_rand());
         $download->save();
     }
     return $a;
 }
开发者ID:hkhateb,项目名称:linet3,代码行数:12,代码来源:Files.php

示例11: save

 public function save($runValidation = true, $attributes = null)
 {
     // Save default store
     if ($this->store_id === 0) {
         Yii::app()->settings->setValue('config_title', $this->name);
         //TODO: Add additional fields here
         return true;
     } else {
         parent::save($runValidation, $attributes);
         //TODO: Add additional config fields here
     }
 }
开发者ID:damnpoet,项目名称:yiicart,代码行数:12,代码来源:Store.php

示例12: save

 public function save($runValidation = true, $attributes = null)
 {
     $user = Yii::app()->user;
     if ($user instanceof CWebUser) {
         $model = self::model()->find(['scopes' => ['active'], 'condition' => 'user_id=:userId AND token=:token AND platform=:platform', 'params' => [':userId' => $user->id, ':token' => $this->token, ':platform' => $this->platform]]);
         if ($model instanceof PushDevice) {
             $this->setIsNewRecord(false);
             $this->setPrimaryKey($model->id);
         }
     }
     return parent::save($runValidation, $attributes);
 }
开发者ID:chervand,项目名称:yii-push,代码行数:12,代码来源:PushDevice.php

示例13: update

 /**
  *### .update()
  *
  * main function called to update column in database
  *
  */
 public function update()
 {
     //get params from request
     $this->primaryKey = yii::app()->request->getParam('pk');
     $this->attribute = yii::app()->request->getParam('name');
     $this->value = yii::app()->request->getParam('value');
     //checking params
     if (empty($this->attribute)) {
         throw new CException(Yii::t('TbEditableSaver.editable', 'Property "attribute" should be defined.'));
     }
     if (empty($this->primaryKey)) {
         throw new CException(Yii::t('TbEditableSaver.editable', 'Property "primaryKey" should be defined.'));
     }
     //loading model
     $this->model = CActiveRecord::model($this->modelClass)->findByPk($this->primaryKey);
     if (!$this->model) {
         throw new CException(Yii::t('TbEditableSaver.editable', 'Model {class} not found by primary key "{pk}"', array('{class}' => get_class($this->model), '{pk}' => is_array($this->primaryKey) ? CJSON::encode($this->primaryKey) : $this->primaryKey)));
     }
     //set scenario
     $this->model->setScenario($this->scenario);
     //commented to be able to work with virtual attributes
     //see https://github.com/vitalets/yii-bootstrap-editable/issues/15
     /*
     //is attribute exists
     if (!$this->model->hasAttribute($this->attribute)) {
     	throw new CException(Yii::t('EditableSaver.editable', 'Model {class} does not have attribute "{attr}"', array(
     	  '{class}'=>get_class($this->model), '{attr}'=>$this->attribute)));
     }
     */
     //is attribute safe
     if (!$this->model->isAttributeSafe($this->attribute)) {
         throw new CException(Yii::t('editable', 'Model {class} rules do not allow to update attribute "{attr}"', array('{class}' => get_class($this->model), '{attr}' => $this->attribute)));
     }
     //setting new value
     $this->setAttribute($this->attribute, $this->value);
     //validate attribute
     $this->model->validate(array($this->attribute));
     $this->checkErrors();
     //trigger beforeUpdate event
     $this->beforeUpdate();
     $this->checkErrors();
     //saving (no validation, only changed attributes)
     if ($this->model->save(false, $this->changedAttributes)) {
         //trigger afterUpdate event
         $this->afterUpdate();
     } else {
         $this->error(Yii::t('TbEditableSaver.editable', 'Error while saving record!'));
     }
 }
开发者ID:upmunspel,项目名称:abiturient,代码行数:55,代码来源:TbEditableSaver.php

示例14: save

 public function save($runValidation = TRUE, $attributes = NULL)
 {
     if ($this->is_active === NULL || $this->is_active == 0) {
         $this->is_active = $this::ACCOUNT_TEAM_MEMBER_IS_DEACTIVATED;
     }
     // check permission
     //		if (!$this->accepting_invitation)
     //		{
     //			if ($this->isNewRecord && !Permission::checkPermission($this, PERMISSION_ACCOUNT_TEAM_MEMBER_CREATE))
     //				return false;
     //			if (!$this->isNewRecord && !Permission::checkPermission($this, PERMISSION_ACCOUNT_TEAM_MEMBER_UPDATE))
     //				return false;
     //		}
     return parent::save($runValidation, $attributes);
 }
开发者ID:Lucerin,项目名称:Yii-projects,代码行数:15,代码来源:AccountTeamMember.php

示例15: save

 public function save($runValidation = true, $attributes = NULL)
 {
     $users = User::model()->findAll();
     parent::save($runValidation, $attributes);
     foreach ($users as $user) {
         if (!UserIncomeMap::model()->findByPk(array('user_id' => $user->id, 'itemVatCat_id' => $this->id))) {
             //'user_id', 'itemVatCat_id'
             $model = new UserIncomeMap();
             $attr = array("user_id" => $user->id, "itemVatCat_id" => $this->id, "account_id" => 100);
             $model->attributes = $attr;
             if (!$model->save()) {
                 return false;
             }
         }
     }
 }
开发者ID:hkhateb,项目名称:linet3,代码行数:16,代码来源:ItemVatCat.php


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