示例#1
0
 protected function save($name, $value, $type)
 {
     if (empty($value)) {
         $this->clear($name);
         return;
     }
     $data = array('owner' => $this->_owner, 'owner_id' => (int) $this->_owner_id, 'name' => $name, 'type' => $type['type'], 'value' => $value);
     switch ($type['type']) {
         case 'file':
             $this->_orm_helper->is_file(TRUE);
             break;
         case 'enum':
         case 'simple':
             $this->_orm_helper->is_file(FALSE);
             break;
     }
     $this->_orm_helper->orm()->clear()->where('owner', '=', $this->_owner)->and_where('owner_id', '=', $data['owner_id'])->and_where('name', '=', $data['name'])->find();
     $validation_ex = Validation_Ext::factory(array('value' => $value));
     if (!empty($type['rules'])) {
         $validation_ex->rules('value', $type['rules']);
     }
     if ($this->_orm_helper->orm()->loaded()) {
         $data['updated'] = date('Y-m-d H:i:s');
         $data['updater_id'] = $this->_user_id;
     } else {
         $data['creator_id'] = $this->_user_id;
     }
     $this->_orm_helper->save($data, $validation_ex);
 }
示例#2
0
文件: base.php 项目: greor/satin-spb
 /**
  * Initializes validation rules, and labels (reloaded method)
  *
  * @return void
  */
 protected function _validation()
 {
     // Build the validation object with its rules
     $this->_validation = Validation_Ext::factory($this->_object)->bind(':model', $this)->bind(':original_values', $this->_original_values)->bind(':changed', $this->_changed);
     foreach ($this->rules() as $field => $rules) {
         $this->_validation->rules($field, $rules);
     }
     // Use column names by default for labels
     $columns = array_keys($this->_table_columns);
     // Merge user-defined labels
     $labels = array_merge(array_combine($columns, $columns), $this->labels());
     foreach ($labels as $field => $label) {
         $this->_validation->label($field, $label);
     }
     foreach ($this->_empty_rules as $name) {
         $this->_validation->add_empty_rule($name);
     }
 }