<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                1.添加路由 ~~~ Route::get('api/:version/product/by_category','api/:version.Product/getAllInCategory'); ~~~ 2.修改database.php數據集返回類型的配置 ~~~ // 數據集返回類型 // 'resultset_type' => 'array', 'resultset_type' => 'collection', ~~~ 3.修改Product.php模型 ~~~ <?php namespace app\api\model; class Product extends BaseModel { protected $autoWriteTimestamp = 'datetime'; protected $hidden = [ 'delete_time', 'main_img_id', 'pivot', 'from', 'category_id', 'create_time', 'update_time']; public function getMainImgUrlAttr($value, $data) { return $this->prefixImgUrl($value, $data); } public static function getMostRecent($count) { $products = self::limit($count) ->order('create_time desc') ->select(); return $products; } //獲取某分類下商品 public static function getProductsByCategoryID($categoryID) { $products=self::where('category_id','=',$categoryID)->select(); return $products; } } ~~~ 4.修改Product.php控制器 ~~~ <?php namespace app\api\controller\v1; use app\api\model\Product as ProductModel; use app\api\validate\Count; use app\api\validate\IDMustBePostiveInt; use app\lib\exception\ProductException; use think\Controller; class Product extends Controller { //獲取指定數量的最近商品 public function getRecent($count = 15) { (new Count())->goCheck(); $products = ProductModel::getMostRecent($count); if ($products->isEmpty()){ throw new ProductException(); } //隱藏summary的方法 $products=$products->hidden(['summary']); return $products; } //獲取某分類下全部商品 public function getAllInCategory($id) { (new IDMustBePostiveInt())->goCheck(); $products = ProductModel::getProductsByCategoryID($id); if ($products->isEmpty()) { throw new ProductException(); } //隱藏summary的方法 $products=$products->hidden(['summary']); return $products; } } ~~~ 結果: ![](https://box.kancloud.cn/63a93c8d3071848ba940afe8f87091ae_1079x649.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>

                              哎呀哎呀视频在线观看