Skip to content

Route mapping rules

Basic rules

WeeSpeed supports RESTful API routing, and the mapping rules are as follows:

Take controller/user.php as an example:

function code_get() method corresponds to GET request/user/code
function code_post() method corresponds to the POST request/user/code
function code_put() method corresponds to PUT request/user/code
function code_delete() method corresponds to the Delete request/user/code

The project supports multi-level routing. Multi-level subdirectories created in the controller directory will be regarded as part of the routing. Take controler/admin/merchant/goods.php as an example:

function goods_get() method corresponds to GET request/admin/merchant/goods
function goods_post() method corresponds to the POST request/admin/merchant/goods
function goods_put() method corresponds to the PUT request/admin/merchant/goodse
function goods_delete() method corresponds to the Delete request/admin/merchant/goods

TIP

WeeSpeed supports all HTTP request methods.

Matching priority

WeeSpeed supports multi-level routing, which is performed in the following order of priority when matching:

  1. Check whether there is a file corresponding to the URL segment in the controller directory.
  2. When the file exists, it detects whether the named method exists in the next paragraph of the URL. If the method exists, it is executed, and subsequent paragraphs of the URL are sequentially passed to the method as execution parameters. If there is no next paragraph, check and execute the index method in the file. If neither exists, an error is returned.
  3. When the file does not exist, check whether the directory named in the next paragraph of the URL exists. If the directory exists, enter the directory and continue the above detection. If the directory does not exist, an error is returned.

TIP

In theory, WeeSpeed supports unlimited routing, but in actual use, it is recommended not to exceed 3 levels.