<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/recent','api/:version.Product/getRecent'); ~~~ 2.新添Count.php驗證器 ~~~ <?php namespace app\api\validate; class Count extends BaseValidate { protected $rule = [ 'count' => 'isPositiveInteger|between:1,15', ]; } ~~~ 3.新建ProductException.php異常類 ~~~ <?php namespace app\lib\exception; class ProductException extends BaseException { public $code = 404; public $msg = '指定商品不存在,請檢查商品ID'; public $errorCode = 20000; } ~~~ 4.更改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; } } ~~~ 5.更改Product .php控制器 ~~~ <?php namespace app\api\controller\v1; use app\api\model\Product as ProductModel; use app\api\validate\Count; 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){ throw new ProductException(); } //隱藏summary的方法 $collection=collection($products); $products=$collection->hidden(['summary']); return $products; } } ~~~ 結果 ![](https://box.kancloud.cn/56af73553aa89b5adab6fc20f6af45f2_973x631.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>

                              哎呀哎呀视频在线观看