IconApiController.class.php
1.59 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/4/11
* Time: 16:31
*/
namespace Apicp\Controller\Operate;
use Common\Service\ClassService;
class IconApiController extends \Apicp\Controller\AbstractController
{
/**
* 栏目接口
* @desc 栏目接口
* @return array
* array(
* 'id' => 0, // 分类 ID
* 'name' => '分类名称', // 分类名称
* 'url' => '分类链接,如果为空,则表明该链接不可直接访问', // 分类链接,如果为空,则表明该链接不可直接访问
* 'upId' => 0, // 上级分类 ID,为 0 则表示顶级
* )
*/
public function Index_post()
{
$classServ = new ClassService();
$classList = $classServ->list_all();
// 格式化数据
$result = [
[
'id' => 0,
'name' => '全部',
'url' => 'Course/Frontend/Index/CourseList/Index?class_id=0',
'upId' => 0,
]
];
if (!empty($classList)) {
foreach ($classList as $v) {
$result[] = [
'id' => rintval($v['class_id']),
'name' => $v['class_name'],
// 只有一级分类可以直接跳转
'url' => $v['parent_id'] == 0 ? 'Course/Frontend/Index/CourseList/Index?class_id=' . $v['class_id'] : '',
'upId' => rintval($v['parent_id']),
];
}
}
$this->_result = $result;
}
}