E
E
EVOSandru62014-11-13 06:57:31
Yii
EVOSandru6, 2014-11-13 06:57:31

How to perform a multi-level menu from a single table in Yii style?

Good afternoon, I used to use such 2 functions to display a hierarchical structure in the form of a multi-level menu. The function is recursive and calls itself. I tried to make it in the Yii style, but so far I'm a little lost in it.
The places are especially confusing - mysql_num rows() , mysql_query(), mysql_fetch_array()
Table Structure - CODE, CODE_PAR,
NAME I haven't changed the function yet. Please help Yii wizards \
[PHP]
public function getCat(){
//$sql = "SELECT CODE, `NAME`, CODE_PAR FROM t_product";
$condition = Product::findAll();
//$result = mysql_query($sql);
//if(!$result) return null;
if(!$condition) return null;
$arr_cat = array();
if(count(Product::model()->findAll()) != 0){
for($i = 0; $i < count(Product::model()->findAll()); $i++){
//$row = mysql_fetch_array($result, MYSQL_ASSOC);
$row = $condition;
//if(empty($arr_cat[$row['CODE_PAR']]))
if(empty($arr_cat[$row->CODE_PAR]))
//$arr_cat[$row['CODE_PAR']][] = array();
$arr_cat[$row->CODE_PAR][] = array();
// $arr_cat[$row['CODE_PAR']][] = $row;
//$arr_cat[$row->CODE_PAR][] = $condition;
$arr_cat[$row->CODE_PAR][] = $row;
}
}
return $arr_cat;
}
public function view_cat($arr, $code_par = 0){
if(empty($arr[$code_par])) return;
echo "

  • ";
    for($i = 0; $i < count($arr[$code_par]); $i++){
    echo '
  • ' .$arr[$code][$i]['TITLE'] ... ';
    $this->view_cat($arr, ($arr[$code_par][$i]['CODE']));
    echo '';
    }
    echo '
';
}
// call
$root = $model->getCat();
$model->view_cat($root);
[/PHP]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Andreevich, 2014-11-13
@reffy

My God, my eyes!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question