3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2187 Views |
-
Convert Array to DataObject

29 September 2010 at 10:53am
Hi,
I've build an array from reading xml file via SimpleXML. So, I want to use that data into template.
How convert array to dataobject?
How save data array to database, thus I've data into db and I made query on it ( more faster then parser remote xml file )?
Thank you
-
Re: Convert Array to DataObject

29 September 2010 at 11:07am
I found this a nice example how to convert a XML Feed to a DataObjectSet:
http://www.i-lateral.com/tutorials/silverstripe-dataobjectset-and-templates/
You can use that example to store the array to a DataObject.
foreach ($someArray as $item){
$obj = new SomeDataObject();
$obj->Title = $item['Title'];
$obj->write();
} -
Re: Convert Array to DataObject

29 September 2010 at 10:23pm
Any DataObject you use for strorage.
class MyItem extends DataObject{}
-
Re: Convert Array to DataObject

30 September 2010 at 12:37am
if your array contains the correct key => data then you can simply do...
$doMyDataObject = new MyDataObject($data);
$doMyDataObject->write();
| 2187 Views | ||
|
Page:
1
|
Go to Top |


