Пример #1
0
 /**
  * 直接保存数据,无需FORM
  */
 static function save_data($name, $data, $nid = null)
 {
     $model = new NodeActiveRecord();
     $data = (object) $data;
     if (!$nid) {
         $nid = $data->id;
     }
     if ($nid) {
         $row = Node::load($name, $nid);
         foreach ($row as $k => $v) {
             $model->{$k} = $v;
         }
     }
     $st = static::tree($name);
     $rt = Node::set_rules($st);
     $model->rules = $rt['rules'];
     return Node::save($name, $model, $data, $nid, true);
 }
Пример #2
0
 /**
  * 设置验证规则
  */
 function set_rules()
 {
     $data = Node::set_rules($this->data);
     //加载插件
     if ($plugins) {
         foreach ($plugins as $pk => $plugin) {
             widget($pk, $plugin);
         }
     }
     $this->attrs = $data['attrs'];
     /**
      * 验证规则赋值给Model中的ruels属性
      */
     $this->model->rules = $data['rules'];
 }