public function index()
 {
     $category = M('category')->order('sort')->select();
     //$category=M('category')->select();
     $category = resortCategory($category);
     //p($category);die;
     $this->category = $category;
     $this->display();
 }
Example #2
0
function resortCategory($category, $parent_id = 0, $level = 0)
{
    static $sort_category = array();
    if ($category) {
        foreach ($category as $key => $value) {
            if ($value['parent_id'] == $parent_id) {
                $value['html'] = str_repeat('|--', $level);
                $sort_category[] = $value;
                echo $level;
                resortCategory($category, $value['category_id'], $level + 1);
            }
        }
    }
    return $sort_category;
}