这是第一次使用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
你告诉它:))好的,我会发布我的答案在下面。 –