On this page
话题分类api开发
创建话题分类相关文件
php
// 创建话题分类控制器
php think make:controller api/v1/TopicClass
// 创建话题分类模型
php think make:model TopicClass
controller层:application\api\controller\v1\TopicClass.php
php
use app\common\model\TopicClass as TopicClassModel;
public function index()
{
// 获取话题分类列表
$list=(new TopicClassModel)->getTopicClassList();
return self::showResCode('获取成功',['list'=>$list]);
}
route层:route\route.php
php
// 不需要验证token
Route::group('api/:version/',function(){
...
// 获取话题分类
Route::get('topicclass','api/v1.TopicClass/index');
...
});
model层:application\common\model\TopicClass.php
php
// 获取所有话题分类
public function getTopicClassList(){
return $this->field('id,classname')->where('status',1)->select();
}