81 throw new CException(Yii::t(
82 'TbEditableSaver.editable',
83 'You should provide modelClass in constructor of EditableSaver.'
91 if (strpos($this->modelClass,
'\\') ===
false) {
92 $this->modelClass = ucfirst($this->modelClass);
105 $this->primaryKey = yii::app()->request->getParam(
'pk');
106 $this->attribute = yii::app()->request->getParam(
'name');
107 $this->
value = yii::app()->request->getParam(
'value');
110 if (empty($this->attribute)) {
111 throw new CException(Yii::t(
'TbEditableSaver.editable',
'Property "attribute" should be defined.'));
113 if (empty($this->primaryKey)) {
114 throw new CException(Yii::t(
'TbEditableSaver.editable',
'Property "primaryKey" should be defined.'));
118 $this->model = CActiveRecord::model($this->modelClass)->findByPk($this->primaryKey);
120 throw new CException(Yii::t(
121 'TbEditableSaver.editable',
122 'Model {class} not found by primary key "{pk}"',
124 '{class}' => get_class($this->model),
125 '{pk}' => is_array($this->primaryKey) ? CJSON::encode($this->primaryKey) : $this->primaryKey
131 $this->model->setScenario($this->scenario);
144 if (!$this->model->isAttributeSafe($this->attribute)) {
145 throw new CException(Yii::t(
147 'Model {class} rules do not allow to update attribute "{attr}"',
149 '{class}' => get_class($this->model),
150 '{attr}' => $this->attribute
159 $this->model->validate(array($this->attribute));
167 if ($this->model->save(
false, $this->changedAttributes)) {
171 $this->
error(Yii::t(
'TbEditableSaver.editable',
'Error while saving record!'));
184 if ($this->model->hasErrors()) {
186 foreach ($this->model->getErrors() as
$attribute => $errors) {
188 $msg = array_merge($msg, $errors);
192 $this->
error($msg[0]);
207 throw new CHttpException($this->errorHttpCode, $msg);
221 $this->model->$name =
$value;
222 if (!in_array($name, $this->changedAttributes)) {
223 $this->changedAttributes[] = $name;
236 $this->raiseEvent(
'onBeforeUpdate', $event);
248 $this->raiseEvent(
'onAfterUpdate', $event);