Example #1
0
 /**
  * 单例
  *
  * @return \Lib\Modelfile
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #2
0
 public function getModelFile()
 {
     if (!class_exists('ModelFile')) {
         require_once CORE_ROOT . MODELS . DIRECTORY_SEPARATOR . 'ModelFile.php';
     }
     if (!is_object($this->file)) {
         $this->file = ModelFile::getInstance();
     }
 }
Example #3
0
 function _init()
 {
     self::$relationships = array('media' => ORM::has_one('\\Model\\Media'));
     self::$fields = array('id' => ORM::field('auto[11]'), 'mime_id' => ORM::field('numeric', array(), 'INT'), 'name' => ORM::field('char[3,155]', array('required', 'max_length[155]')), 'path' => ORM::field('char[3,255]', array('required', 'max_length[255]')), 'modified' => ORM::field('datetime'), 'created' => ORM::field('datetime'));
     $this->ts_fields = array('modified', '[created]');
 }
 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();
     }
 }
 public function handleForm()
 {
     $data;
     if ($this->setup["method"] == "get") {
         $data = Yii::app()->controller->input_get($this->getFormName());
     } else {
         // post
         $data = Yii::app()->controller->input_post($this->getFormName());
     }
     if ($data === false) {
         return false;
     }
     $this->setAttributes($data);
     ModelFile::findFromInput($this->getFormName(), $this);
     $result = $this->validate();
     if (!$result) {
         $this->onFormValidatedFail();
         return false;
     }
     $result = $this->onFormValidatedSuccess();
     if (!$result) {
         return false;
     }
     $this->onFormDone();
     return true;
 }