Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

print array ,another problem

Go to End

2 Posts   801 Views


Community Member, 181 Posts

11 January 2012 at 10:36pm


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) >>>>>>

    [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:

- test 2011
- test v2 2011

- test 2010



Community Member, 59 Posts

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 ( 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 ;)).