In SS 2.4 I often use array to store data that is accessible in both PHP and JavaScript. I use DataObjectSet to transform the array data to iterate over in a template.
2.4:
<?php
class Page extends SiteTree {
function TestIt() {
$a = array(
'one' => array('ID' => 'somedata', 'Name' => 'Name some data'),
'two' => array('ID' => 'moredata', 'Name' => 'Name some data'),
);
$al = new DataObjectSet($a);
// Debug::Show($a);
// Debug::Show($al);
return $al;
}
}
Template:
<% control TestIt %><div>$ID $Name</div><% end_control %>
However, in 3.0 DataObjectSet is no longer available. The message tells me to use DataList or ArrayList instead.
DataList is out as it gives an error it needs table definition
[User Error] DataObject::buildSQL: Can't find data classes (classes linked to tables) for Array. Please ensure you run dev/build after creating a new DataObject.
And if I try using an ArrayList it doesn't show $ID or $Name. Should I be using a different approach or report a bug?
Cheers,
Marijn.