/** * ajax请求树 * * @return string */ function ajaxtree() { $icon = array("icon-state-warning", "icon-state-success", "icon-state-danger", "icon-state-info"); if ($this->get->parent == '#') { $parent = 0; } else { $parent = $this->get->parent; } if (validate::int($parent)) { $categoryModel = $this->model('category'); $result = $categoryModel->fetchChild($parent); $tree = array(); foreach ($result as $category) { $temp = array(); $temp['id'] = $category['id']; $temp['text'] = $category['name']; $temp['icon'] = "fa fa-folder icon-lg " . $icon[array_rand($icon)]; //$temp['icon'] = 'http://localhost/home/application/assets/gravatar.jpg'; $result = $categoryModel->fetchChild($category['id']); $temp['children'] = !empty($result); if ($parent == 0) { $temp['type'] = 'root'; } $tree[] = $temp; } return new json($tree); } return new json(json::PARAMETER_ERROR, '错误的分类id'); }