Ejemplo n.º 1
0
 function run()
 {
     if ($this->nid > 0) {
         /**
          * 如果有nid,说明是更新
          * 需要先取出NODE的内容并赋值给model
          */
         $row = Node::load($this->name, $this->nid);
         foreach ($row as $k => $v) {
             $this->model->{$k} = $v;
         }
     }
     $data['model'] = $this->model;
     //设置字段验证规则
     $this->set_rules();
     if ($_POST && \Yii::$app->request->isAjaxRequest) {
         //保存数据到数据库
         $attrs_data = array();
         foreach ($this->attrs as $get) {
             $attrs_data[$get] = $_POST['NodeActiveRecord'][$get];
         }
         Node::save($this->name, $this->model, $attrs_data, $this->nid);
     }
     $data['nid'] = $this->nid;
     $data['data'] = $this->data;
     $data['message'] = $this->message;
     $data['script'] = $this->script;
     echo $this->render('@app/modules/content/models/FormBuilderView', $data);
 }
Ejemplo n.º 2
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);
 }