本文整理汇总了PHP中CActiveRecord::getError方法的典型用法代码示例。如果您正苦于以下问题:PHP CActiveRecord::getError方法的具体用法?PHP CActiveRecord::getError怎么用?PHP CActiveRecord::getError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CActiveRecord
的用法示例。
在下文中一共展示了CActiveRecord::getError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
}
示例2: textInputFull
public static function textInputFull(CActiveRecord $model, $fieldName, $options = array())
{
$containerCss = '';
$options['class'] = 'form-control';
if (array_key_exists('inputClass', $options)) {
$options['class'] .= " {$options['inputClass']}";
unset($options['inputClass']);
}
if (array_key_exists('fieldColumn', $options)) {
$columns = $options['fieldColumn'];
unset($options['fieldColumn']);
} else {
$columns = self::$fullColumn;
}
$errorHelp = '';
if ($model->hasErrors($fieldName)) {
$containerCss .= ' has-error';
$errorHelp = '<span class="help-block">' . $model->getError($fieldName) . '</span>';
}
$str = "<div class=\"form-group{$containerCss}\">";
if (array_key_exists('hasLabel', $options)) {
$str .= '<div class="input-caption col-md-' . $columns . '">' . CHtml::activeLabelEx($model, $fieldName, array('class' => 'control-label')) . '</div>';
unset($options['hasLabel']);
}
$str .= "<div class=\"col-md-{$columns}\">" . CHtml::activeTextField($model, $fieldName, $options) . "{$errorHelp}</div></div>";
return $str;
}