1

I am using the DataMapper ORM in my CodeIgniter project.

The problem I am having is, when I use the following codes:

$o = new Object();
$o->get();

The $o becomes a DataMapper ORM collection object rather than an array.

I know I can still use foreach to loop through the collection but other PHP array functions (such as array_pop,array_splice) still can not be used on it.

I would like to know if there is any function provided by DataMapper ORM to return it as an array.

Many thanks to you all.

tereško
  • 58,060
  • 25
  • 98
  • 150
bobo
  • 8,439
  • 11
  • 57
  • 81

1 Answers1

4

Use DataMapper's $o->all property instead of the $o->get() method to return an array.

65Fbef05
  • 4,492
  • 1
  • 22
  • 24
  • $o->All Doesn't return all values if there is related objects. – Mukesh Yadav May 25 '11 at 13:40
  • 2
    Relations are only fetched on the current object. $o->all is an array of objects. If arrays are needed, you can use the Array extension, which introduces the to_array() and all_to_array() methods. – WanWizard Jan 31 '12 at 16:04