后台控制器是专门给后台用的,只有加入后台管理员角色才能访问对应的接口,而前台控制器是对外开放的专门给前端程序对接的接口,比如APP/小程序/网站等。 以文章分类为例,我们应该在actionphp/application/example/controller目录下建立Cate.php控制器文件,内容如下: ![](https://box.kancloud.cn/f5f9815e2f9bf260eb01af71070d4cf0_925x729.png) ``` <?php /** * +---------------------------------------------------------------------- * | InitAdmin/actionphp [ InitAdmin渐进式模块化通用后台 ] * +---------------------------------------------------------------------- * | Copyright (c) 2018-2019 http://initadmin.net All rights reserved. * +---------------------------------------------------------------------- * | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) * +---------------------------------------------------------------------- * | Author: jry <ijry@qq.com> * +---------------------------------------------------------------------- */ namespace app\example\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]]); } } ```