zoukankan      html  css  js  c++  java
  • 全栈微信小程序商城 学习笔记8.4 category分类接口编写

    相关表字段一览

    category表

    id	
    name	分类名称
    topic_img_id	外键,关联image表
    delete_time	
    description	描述
    update_time	
    

    准备工作

    application oute.php

    Route::get('api/:version/category/all', 'api/:version.Category/getAllCategories');
    

    异常处理

    applicationlibexceptionCategoryException.php

    <?php
    
    namespace applibexception;
    
    
    class CategoryException extends BaseException
    {
        public $code = 404;
        public $msg = '指定类目不存在,请检查商品ID';
        public $errorCode = 20000;
    }
    

    Category模型

    applicationapimodelCategory.php

    class Category extends BaseModel
    {
        public function img()
        {
            return $this->belongsTo('Image', 'topic_img_id', 'id');
        }
    }
    

    Category控制器

    applicationapicontrollerv1Category.php

    class Category
    {
        public function getAllCategories()
        {
            $categories = CategoryModel::all([], 'img'); 
            if($categories -> isEmpty()){
               throw new CategoryException();
            }
            return $categories;
        }
    }
    

    测试

  • 相关阅读:
    JavaScript中的的面向对象中的一些知识
    JavaScript中的Function
    jq 表格全选案例
    jq 美女相册案例
    jq 属性操作
    jq tab图片切换
    jq class操作
    jq css操作
    jquery 淘宝案例
    jquery 鼠标点击下滑案例
  • 原文地址:https://www.cnblogs.com/Qyhg/p/14764777.html
Copyright © 2011-2022 走看看