3060 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 258 Views |
-
print array ,another problem

11 January 2012 at 10:36pm
hi
i cant find any solution for my problem (probably pretty easy)
i have an array
$array = array();
$data = DataObject::get('ModulKalendariumRok');
foreach ($data as $row) {
$data = DataObject::get('ModulKalendarium', "Rok = '$row->Rok'");
foreach ($data as $row) {
$array['Kalendarium'][$row->Rok][] = $row->Wydarzenie;
}
}return new ArrayData($array);
>>>>>> print_r($array) >>>>>>
Array
(
[Kalendarium] => Array
(
[2011] => Array
(
[0] => test 2011
[1] => test v2 2011
)[2010] => Array
(
[0] => test 2010
))
)
how to display it in the template to getting something like this:
2011
- test 2011
- test v2 20112010
- test 2010?
-
Re: print array ,another problem

12 January 2012 at 12:56am
Hi snaip,
assuming that you create the array() within an Model extending Page / SiteTree I guess I would create a DataObjectSet (http://api.silverstripe.org/2.4/sapphire/model/DataObjectSet.html) and return it to the Template. There you can loop it as a control.
Besides that I think that you should try to get this DataObjectSet directly from DB, without writing it into an array first and than back. Also I would try to get the Set with just one request. Doing DB-Requests (DataObject::get()) within a loop are not ideal for system performance and can be usually replaced by a single one (that's what databases live for ;)).
Regards
SF.
| 258 Views | ||
|
Page:
1
|
Go to Top |


