remplisage tableau via fonction récursive
Bonjour,
J'ai encore besoin de vos lumières pour l'enregistrement d'un tableau avec une fonction récursive .
voilà ma fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
public function GetMenu($uid,$level='0'){
$Param = array('id'=> $uid,'pid'=>$level);
$query = "SELECT P.page_id,P.parent_id,P.page_name,P.url,P.hierarchy
FROM ".$this->__get('db_prefix')."_backend_pages P
INNER JOIN ".$this->__get('db_prefix')."_groups G ON FIND_IN_SET( G.group_id, P.group_id )
INNER JOIN ".$this->__get('db_prefix')."_users U ON U.group_id = G.group_id
WHERE U.user_id = :id AND P.parent_id = :pid ORDER BY hierarchy";
$menu = $this->GetDb()->read( $query,$Param);
for($i = 0 ; $i < count($menu); $i++) {
$ListItem[$i] = array('page_id'=>$menu[$i]['page_id'],'parent_id'=>$menu[$i]['parent_id'],'page_name'=>constant($menu[$i]['page_name']),'url'=>$menu[$i]['url']);
array_push($ListItem[$i],self::GetMenu($uid,$menu[$i]['page_id']));
}
return $ListItem;
} |
La fonction read retourne une tableau via "fetchAll()"
Ce que j'obtiens :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
Array (
[0] => Array (
[page_id] => 1 [parent_id] => 0 [page_name] => page1 [url] => page1.php
[0] => Array (
[0] => Array (
[page_id] => 8 [parent_id] => 1 [page_name] => page1_1 [url] => page1_1.php
[0] =>
)
[1] => Array (
[page_id] => 9 [parent_id] => 1 [page_name] => page1_2 [url] => page1_2.php
[0] =>
)
[2] => Array (
[page_id] => 10 [parent_id] => 1 [page_name] => page1_3 [url] => page1_3.php
[0] =>
)
)
)
[1] => Array (
[page_id] => 2 [parent_id] => 0 [page_name] => page2 [url] => page2.php
[0] => Array (
[0] => Array (
[page_id] => 11 [parent_id] => 2 [page_name] => page2_1 [url] => page2_1.php
[0] =>
)
)
)
) |
Ce que je voudrais obtenir :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Array (
[0] => Array (
[page_id] => 0 [parent_id] => 0 [page_name] => page1 [page_url] => page1.php
[0] => Array ( [page_id] => 8 [parent_id] => 0 [page_name] => page1_1 [page_url] => page1_1.php )
[1] => Array ( [page_id] => 9 [parent_id] => 0 [page_name] => page1_2 [page_url] => page1_2.php )
)
[1] => Array(
[page_id] => 0 [parent_id] => 0 [page_name] => page2 [page_url] => page2.php
[0] => Array ( [page_id] => 8 [parent_id] => 0 [page_name] => page2_1 [page_url] => page2_1.php )
[1] => Array ( [page_id] => 9 [parent_id] => 0 [page_name] => page2_2 [page_url] => page2_2.php )
)
) |
Ce tableau me permettra d'afficher un menu dans un template smarty.
une idée ?
Merci.