Im a newbie in CodeIgniter.
I have created model for Pizza table and Ingredients table. Tables are joined by additional Pizza_Ingredients table (its many to many relation).
My model:
<?php
class Pizza extends DataMapper {
var $table = 'Pizza';
var $has_many =
array(
'ingredients' =>
array(
'class' => 'ingredients',
'join_table' => 'pizza_ingredients'
)
);
}
class Ingredients extends DataMapper {
var $table = 'Ingredients';
var $has_many =
array(
'pizza' =>
array(
'class' => 'pizza',
'join_table' => 'pizza_ingredients'
)
);
}
?>
When I get data using that code:
$pm = new Pizza();
$pm->include_related('ingredients');
$array = $pm->get();
im getting array which has duplicated Pizza values (it looks like just sql query result).
margherita | cheese
vegetariana | vegetable 1
vegetariana | vegetable 2
I can't simple generate html table in "foreach" on array like this.
i want to get object, that has structure like this:
margherita:
- cheese
vegetariana:
- vegetable 1
- vegetable 2
that allows me to make foreach loop (with pizzas) with other foreach loop (with ingredients) inside "pizza loop".
I have to write this in PHP, or CodeIgniter/DataMapper can do something more for me?
Any advice?