0
<?xml version="1.0" encoding="utf-8"?>
<products>
<category categoryName="Electronics">
<product productName="Camera Lenses Collection" productID="DSCF0001"     thumbPath="thumbs/Electronics/camera_lenses_collection-other.jpg" productPrice="250.50">
<sizes>
<size>10</size>
<size>20</size>
<size>30</size>
<size>40</size>
<size>50</size>
</sizes>
<colors>
<color>Red</color>
<color>Blue</color>
<color>Green</color>
<color>Yellow</color>
<color>Pink</color>
</colors>
</category>
</product>
</products> 

-こんにちは、ループ経由でテーブルからここにデータをロードする必要があります。データベースからxmlファイルを生成する方法を教えてください。

4

1 に答える 1

0

データベースから xml ファイルを生成するのは簡単です。これに従うだけでループは必要ありません。

モデル機能

function getDataForXML(){
   return $query = $this->db->get('my_table');
   //Here you should note i am returning 
   //the query object instead of 
   //$query->result() or $query->result_array()
}  

コントローラ

function get_report()
{
    $this->load->model('my_model');
    $this->load->dbutil();
    $this->load->helper('file');
    // get the object
    $report = $this->my_model->getDataForXML();
    //pass it to db utility function
    $new_report = $this->dbutil->xml_from_result($report);
    //Now use it to write file. write_file helper function will do it
    write_file('xml_file.xml',$new_report);
    //Done
}

そして、xml_file.xml という名前の新しいファイルが利用可能になりました!

資力

データベース ユーティリティ クラス

ファイルヘルパー

于 2013-03-15T14:27:21.790 に答える