[eluser]MEM[/eluser]
The fighting days are not over, I'm killing myself on this.
With the help of great gurus (credits to oddz on sitepoint forums), I was able to create a model that returns an array like this:
Code:
Array (
[0] => Array (
[id_cat] => 6
[nome_cat] => Fitofármacos
[parent_id_cat] => 1
[children] => Array (
[0] => Array (
[id_cat] => 9
[nome_cat] => Herbicidas
[parent_id_cat] => 6
[children] => Array ( )
)
[1] => Array (
[id_cat] => 10
[nome_cat] => Insecticidas
[parent_id_cat] => 6
[children] => Array ( )
)
[2] => Array (
[id_cat] => 11
[nome_cat] => Fungicidas
[parent_id_cat] => 6
[children] => Array ( )
)
)
)
[1] => Array (
[id_cat] => 7
[nome_cat] => Adubos
[parent_id_cat] => 1
[children] => Array ( )
)
[2] => Array (
[id_cat] => 8
[nome_cat] => Sementes
[parent_id_cat] => 1
[children] => Array ( )
)
)
This exact structure I have passed to my view file. So, the "only" think I have to do is to play with this hierarchy and with the URI segment values.
This array is called $menucategorias
I'm having this:
Code:
foreach ($menucategorias as $mainitem)
{
//hoping to get parent...
echo $mainitem['nome_cat'];
if($CI->uri->segment(3)==$mainitem['parent_id_cat'])
{
//hopping to get parent and...
echo $mainitem['nome_cat'];
//hoping to get childs...
foreach ($mainitem['children'] as $subitem)
{
echo $subitem['nome_cat'];
}
}
}
But I can only hope. Since I'm always getting the childrens only, and never the parents.
~~~~~