ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
后台控制器是专门给后台用的,只有加入后台管理员角色才能访问对应的接口,而前台控制器是对外开放的专门给前端程序对接的接口,比如APP/小程序/网站等。 以文章分类为例,我们应该在/application/cms/controller目录下建立Cate.php控制器文件,内容如下: ![](https://box.kancloud.cn/f5f9815e2f9bf260eb01af71070d4cf0_925x729.png) ``` <?php /** * +---------------------------------------------------------------------- * | UniAdmin [ 渐进式模块化通用后台 ] * +---------------------------------------------------------------------- * | Copyright (c) 2018-2020 http://uniadmin.jiangruyi.com All rights reserved. * +---------------------------------------------------------------------- * | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) * +---------------------------------------------------------------------- * | Author: jry <ijry@qq.com> * +---------------------------------------------------------------------- */ namespace app\cms\controller; use think\Db; use think\Request; use app\core\controller\common\Home; use \Firebase\JWT\JWT; //导入JWT /** * 文章分类控制器 * * @author jry <ijry@qq.com> */ class Cate extends Home { private $example_cate; protected function initialize() { parent::initialize(); $this->example_cate = new \app\example\model\Cate(); } /** * 获取分类信息 * * @return \think\Response * @author jry <ijry@qq.com> */ public function info($id) { $ret = $this->is_login(); if($ret['code'] != 200){ return json($ret); } $user_info = $this->example_cate ->field('id,title,status') ->find($if); return json(['code' => 200, 'msg' => '分类信息', 'data' => ['info' => $info]]); } } ```