這是第一次使用CakePHP的XML函數。CakePHP的Xml到數組到數據庫
我已經建立了這種模式:
<?php
class Importer extends AppModel {
var $name = 'Importer';
var $useTable = false;
function import_deals(){
// import XML class
App::import('Xml');
// your XML file's location
$file = "../webroot/files/datafeed_114532.xml";
// now parse it
$parsed_xml =& new XML($file);
$parsed_xml = Set::reverse($parsed_xml); // this is what i call magic
// see the returned array
debug($parsed_xml);
}
}
控制器:
<?php
class ImporterController extends AppController {
var $name = 'Importer';
var $uses = array('Importer', 'City', 'Deal', 'Partner');
function import_deals($parsed_xml) {
$this->loadModel('Importer');
$deals = $this->Importer->find('all');
$this->set('deals', $deals);
}
}
我不知道,因爲我基本上希望它把XML數據到數據庫的視圖。該XML數組類似:
Array (
[MerchantProductFeed] => Array (
[Merchant] => Array (
[0] => Array (
[id] => 2891
[Prod] => Array (
[0] => Array (
[id] => 175029851
[web_offer] => yes
[Text] => Array (
[name] => London South: 60% Off Takeaways From Just-Eat
[desc] => £6 for £15 Worth of Takeaways From Over 1000 London Eateries with Just-Eat
[promo] => 60 %
)
[Uri] => Array (
[awTrack] => http://www.awin1.com/pclick.php?p=175029851&a=114532&m=2891
[mImage] => http://static.groupon.co.uk/44/30/1311759403044.jpg
)
[Price] => Array (
[rrp] => 15.00
)
[Cat] => Array (
[awCatId] => 100
[awCat] => Bodycare & Fitness
[mCat] => Deals
)
[brand] => Array()
[valFrom] => 2011-07-29
[valTo] => 2011-10-29
)
[1] => Array (
[id] => 175030161
[web_offer] => yes
[Text] => Array (
[name] => Essex: Up to 70% Off Treatment and Cut and Blowdry OR Half Head Highlights or Colour
[desc] => Cut, Blow Dry and Paul Mitchell Treatment (£18) Or Add Half Head of Highlights or Colour (£34) at Cube (Up to 70% Saving)
[promo] => 70 %
)
[Uri] => Array (
[awTrack] => http://www.awin1.com/pclick.php?p=175030161&a=114532&m=2891
[mImage] => http://static.groupon.co.uk/53/51/1311615285153.jpg
)
[Price] => Array (
[rrp] => 60.00
)
[Cat] => Array (
[awCatId] => 100
[awCat] => Bodycare & Fitness
[mCat] => Deals
)
[brand] => Array()
[valFrom] => 2011-07-29
[valTo] => 2011-10-28
)
....
任何幫助,將不勝感激,即使你可以點我在正確的方向:)謝謝你們
戴夫
所以有什麼問題?您獲得了數據,您可以對模型進行保存以將其保存在數據庫中。 –
但它怎麼會知道在哪裏把數據大聲笑因爲數據已被放到多個表和字段:) – Dave
你告訴它:))好的,我會發布我的答案在下面。 –