protected function tableUpdate($table) { $editable = $table["actions"]["_edit"]; $modelClass = $table["model"]; if (!is_array($editable) || !isset($editable[0])) { $this->returnError(); return; } $id = $this->input_post($table["primary"]); if ($this->input_get("multiple")) { $objects = $modelClass::model()->updateAll($this->input_post("attrs"), $table["primary"] . " in (" . implode(",", $id) . ") "); $this->returnSuccess(); return; } $criteria = new CDbCriteria(); if ($table["condition"]) { foreach ($table["condition"] as $key => $val) { if (is_numeric($key)) { $criteria->addCondition($val); continue; } $criteria->compare($key, $val, false, "AND", false); } } $attr = array(); $attr[$table["primary"]] = $id; $object = $modelClass::model()->findByAttributes($attr, $criteria); if (!$object) { $this->returnError("This item does not exist"); return; } $object->scenario = $table["updateScenario"]; if ($table["formUpload"]) { ModelFile::findFromInputSingle($object); } foreach ($editable as $column) { $this->handleUpdateField($object, $column, $table); } if (!$object->save(true)) { $this->returnError(Util::getFirstError($object), array("errors" => $object->getErrors())); } else { $this->returnSuccess(); } }