<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                1.在配置中開啟路由完整匹配 ~~~ // 路由使用完整匹配 //'route_complete_match' => false, 'route_complete_match' => true, ~~~ 2.書寫主題路由 ~~~ Route::get('api/:version/theme','api/:version.Theme/getSimpleList'); Route::get('api/:version/theme/:id','api/:version.Theme/getComplexOne'); ~~~ 3.新建Product.php模型 ~~~ <?php namespace app\api\model; class Product extends BaseModel { } ~~~ 4.新建Theme.php模型 ~~~ <?php namespace app\api\model; class Theme extends BaseModel { protected $hidden = ['delete_time', 'topic_img_id', 'head_img_id']; public function topicImg() { return $this->belongsTo('Image', 'topic_img_id', 'id'); } public function headImg() { return $this->belongsTo('Image', 'head_img_id', 'id'); } //關聯product,多對多關系 public function products() { return $this->belongsToMany( 'Product', 'theme_product', 'product_id', 'theme_id'); } } ~~~ 5.更改BaseValidate.php驗證器 ~~~ <?php namespace app\api\validate; use app\lib\exception\ParameterException; use think\Request; use think\Validate; class BaseValidate extends Validate { public function goCheck() { // 獲取http傳入的參數 // 對這些參數做檢驗 $request = Request::instance(); $params = $request->param(); $result = $this->batch()->check($params); if(!$result){ $e =new ParameterException(); $e->msg=$this->error; throw $e; //$error = $this->error; //throw new Exception($error); } else{ return true; } } protected function isPositiveInteger($value, $rule='', $data='', $field='') { if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) { return true; } return false; //return $field . '必須是正整數'; } } ~~~ 6.更改IDMustBePostiveInt.php驗證器 ~~~ <?php namespace app\api\validate; use think\Validate; class IDMustBePostiveInt extends BaseValidate { protected $rule = [ 'id' => 'require|isPositiveInteger', // 'num'=>'in:1,2,3' ]; protected $message = [ 'id' => 'id必須是正整數' ]; } ~~~ 7.新建IDCollection.php驗證器 ~~~ <?php namespace app\api\validate; class IDCollection extends BaseValidate { // 千萬不要在require | checkIDS中加空格 // 不然你會哭的 // 源碼中是沒有去處多余空格的判斷的 // 這將導致驗證不執行 protected $rule = [ 'ids' => 'require|checkIDs' ]; protected $message = [ 'ids' => 'ids參數必須為以逗號分隔的多個正整數,仔細看文檔啊' ]; protected function checkIDs($value) { $values = explode(',', $value); if (empty($values)) { return false; } foreach ($values as $id) { if (!$this->isPositiveInteger($id)) { // 必須是正整數 return false; } } return true; } } ~~~ 8.新建ThemeException .php異常類 ~~~ <?php namespace app\lib\exception; class ThemeException extends BaseException { public $code = 404; public $msg = '指定主題不存在,請檢查主題ID'; public $errorCode = 30000; } ~~~ 9.新建Theme.php控制器 ~~~ <?php namespace app\api\controller\v1; use app\api\validate\IDCollection; use app\api\model\Theme as ThemeModel; use app\lib\exception\ThemeException; use think\Controller; class Theme extends Controller { public function getSimpleList($ids = '') { $validate = new IDCollection(); $validate->goCheck(); $ids = explode(',', $ids); $result = ThemeModel::with('topicImg,headImg')->select($ids); if (!$result) { throw new ThemeException(); } return $result; } public function getComplexOne($id) { return "1111"; } } ~~~ 結果 ![](https://box.kancloud.cn/18864cfcab9332a9c024750ce7e63ba1_944x661.png) ![](https://box.kancloud.cn/77484c3469f11d155e51bd1484b134fb_660x507.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看