How to design the directory structure of thinkphp5 Restful API version (multi-module)

problem description

A set of interfaces developed by tp5 and a mall for multi-end use are intended to make interface version division. The situation is as follows:

  • API code, PC side and WAP side should be placed under the same tp5 application, because the domain name can only provide one..
  • Interface is multi-module, such as user, order, merchandise, etc.

at present, the directory structure is like this, and it has not been used for API version partition

.
+ application
    + admin   // 
    + wap    // WAP
    + api_users    // 
        + controller
            + Users    // 
            + Accounts    // 
    + api_goods    // 
    + api_orders    // 
    + common    // 
    + ...

is intended to be designed like this, but tp5 does not seem to support it, and the request cannot be found

+ application
    + admin
    + wap
    + v1
        + users
            + controller
                + Users
                + Accounts
        + goods 
    + v2 

under this requirement, how to design the directory structure if you want to add the interface version division?

Apr.15,2021

  • application
    + api

    +controller
       +v1

that's fine. Use Route::get ('api/:ver/user',' api/:ver.User') when routing;


what did you do in the end?

Menu