Пример #1
0
    $root = $xml->baseInfoTable->row[$ret];
    if ($str['client_dbfield'] != null && $str['client_name'] != null && $str['client_id'] != null) {
        $new_item = $root->addChild('item');
        add_new_item($new_item, $str);
        echo "添加成功!!" . "<br />";
        $xml->asXML($data);
    } else {
        echo "添加失败……";
    }
} else {
    if ($lenth == 3) {
        $root = $xml->baseInfoTable;
        if ($str['client_dbfield'] != null && $str['client_name'] != null && $str['client_id'] != null) {
            $new_row = $root->addChild('row');
            $new_item = $new_row->addChild('item');
            add_new_item($new_item, $str);
            echo "添加成功!!" . "<br />";
            $xml->asXML($data);
        } else {
            echo "添加失败……";
        }
    }
}
?>



	
	

Пример #2
0
<?php

include "script.php";
add_new_item($_POST["sku"], $_POST["item_name"], $_POST["item_description"]);
Пример #3
0
 public function ajaxAddClient()
 {
     //header('Content-type: Application/json',true);
     $req = $this->input->post();
     if (empty($req)) {
         return false;
     }
     function add_new_item($new_item, $req)
     {
         $new_item->addChild("id", $req['client_id']);
         $new_item->addChild("dbfield", $req['client_dbfield']);
         $new_item->addChild("type", $req['client_type']);
         $new_item->addChild("name", $req['client_name']);
         $new_item->addChild("colspan", $req['client_colspan']);
         $new_item->addChild("lspace", $req['client_lspace']);
         $new_item->addChild("width", $req['client_width']);
         $new_item->addChild("height", $req['client_height']);
         $new_item->addChild("valuesource", $req['client_valuesource']);
     }
     function serch_insert_post($xml, $cout)
     {
         for ($i = 0; $i < $cout; $i++) {
             $lenth = count($xml->baseInfoTable->row[$i]->item);
             if ($lenth < 3) {
                 return $i;
             }
         }
     }
     $data = "./layoutxml/beijing-jiaoyu.xml";
     $xml = simplexml_load_file($data);
     //创建 SimpleXML对象
     $res = "";
     //判断标志位
     $cont = 0;
     $cout = count($xml->baseInfoTable->row);
     //计算row的个数
     $lenth = count($xml->baseInfoTable->row[$cout - 1]->item);
     //返回最后一个row中item的个数
     $ret = serch_insert_post($xml, $cout);
     if ($cout == 0) {
         $root = $xml->baseInfoTable;
         $new_row = $root->addChild('row');
         $new_item = $new_row->addChild('item');
         add_new_item($new_item, $req);
         $xml->asXML($data);
         $res = "添加成功!!";
         $cont = 1;
         //echo $cout;
     } else {
         if ($lenth < 3) {
             $root = $xml->baseInfoTable->row[$ret];
             $new_item = $root->addChild('item');
             add_new_item($new_item, $req);
             $xml->asXML($data);
             $res = "添加成功!!";
             $cont = 1;
         } else {
             if ($lenth == 3) {
                 $root = $xml->baseInfoTable;
                 $new_row = $root->addChild('row');
                 $new_item = $new_row->addChild('item');
                 add_new_item($new_item, $req);
                 $xml->asXML($data);
                 $res = "添加成功!!";
                 $cont = 1;
             }
         }
     }
     if ($cont) {
         $this->load->model('dynamicui_model');
         $model = new Dynamicui_model();
         $data_r = array_combine($model->getGerendata(), $model->getGereniddata());
     } else {
         $data_r = "";
     }
     $ret = array();
     $ret["cont"] = $cont;
     $ret["res"] = $res;
     $ret["data"] = $data_r;
     echo json_encode($ret);
 }