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


PHP CActiveRecord::setScenario方法代码示例

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


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

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

示例2: update

 /**
  * main function called to update column in database
  *
  */
 public function update()
 {
     //set params from request
     $this->primaryKey = yii::app()->request->getParam('pk');
     $this->attribute = yii::app()->request->getParam('name');
     $value = Yii::app()->request->getParam('value');
     //checking params
     if (empty($this->attribute)) {
         throw new CException(Yii::t('zii', 'Property "attribute" should be defined.'));
     }
     if (empty($this->primaryKey)) {
         throw new CException(Yii::t('zii', 'Property "primaryKey" should be defined.'));
     }
     //loading model
     $this->model = CActiveRecord::model($this->modelClass)->findByPk($this->primaryKey);
     if (!$this->model) {
         throw new CException(Yii::t('editable', 'Model {class} not found by primary key "{pk}"', array('{class}' => get_class($this->model), '{pk}' => $this->primaryKey)));
     }
     $this->model->setScenario($this->scenario);
     //is attribute exists
     if (!$this->model->hasAttribute($this->attribute)) {
         throw new CException(Yii::t('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('zii', '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, $value);
     //validate
     $this->model->validate(array($this->attribute));
     if ($this->model->hasErrors()) {
         $this->error($this->model->getError($this->attribute));
     }
     //save
     if ($this->beforeUpdate()) {
         //saving (only chnaged attributes)
         if ($this->model->save(false, $this->changedAttributes)) {
             $this->afterUpdate();
         } else {
             $this->error(Yii::t('zii', 'Error while saving record!'));
         }
     } else {
         $firstError = reset($this->model->getErrors());
         $this->error($firstError[0]);
     }
 }
开发者ID:janym,项目名称:angular-yii,代码行数:51,代码来源:TbEditableSaver.php

示例3: setModelAttributes

 /**
  * Sets model fields using the provided attributes and values.
  *
  * @param CActiveRecord $model the model to set fields on
  * @param array $attributes an associative array of attributes
  * @param array $params the params array passed to X2Flow::trigger()
  * @return boolean whether or not the attributes were valid and set successfully
  *
  */
 public function setModelAttributes(&$model, &$attributeList, &$params)
 {
     $data = array();
     foreach ($attributeList as &$attr) {
         if (!isset($attr['name'], $attr['value'])) {
             continue;
         }
         if (null !== ($field = $model->getField($attr['name']))) {
             // first do variable/expression evaluation, // then process with X2Fields::parseValue()
             $type = $field->type;
             $value = $attr['value'];
             if (is_string($value)) {
                 if (strpos($value, '=') === 0) {
                     $evald = X2FlowFormatter::parseFormula($value, $params);
                     if (!$evald[0]) {
                         return false;
                     }
                     $value = $evald[1];
                 } elseif ($params !== null) {
                     if (is_string($value) && isset($params['model'])) {
                         $value = X2FlowFormatter::replaceVariables($value, $params, $type);
                     }
                 }
             }
             $data[$attr['name']] = $value;
         }
     }
     if (!isset($model->scenario)) {
         $model->setScenario('X2Flow');
     }
     $model->setX2Fields($data);
     if ($model instanceof Actions && isset($data['complete'])) {
         switch ($data['complete']) {
             case 'Yes':
                 $model->complete();
                 break;
             case 'No':
                 $model->uncomplete();
                 break;
         }
     }
     return true;
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:52,代码来源:X2FlowAction.php


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