Design problem of interface returning code in thinkPHP5

I want to use the return method that comes with the Controller class to return interface information. Among them, code code I want to first define a list of constants, and then make it easy for all Controller layers to use.

first I write a base class of the control layer, in which the code code is defined as a static property. Its subclasses can then refer to the defined code through $this::CODE_NAMEl.

clipboard.png

clipboard.png

although the effect has been achieved, it feels a little wrong. Please tell me how to design this situation in general. Thank you:)

Php
Jun.03,2021

first of all, the problem with your separate writing is that it is placed in the base class, which is obviously not necessary.
this is best placed in a separate Response class, where some common return code class constants are defined, or a separate class is used to put

  • 200request succeeded
  • 401001 TOKEN failure
  • 404001 Resource does not exist
  • et al.

only defines some common ones. If the business logic needs to return different code , then the code of the corresponding business should put class constants in your business implementation class to ensure that this code can easily and quickly locate problems in the current business logic.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e65887-674d9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e65887-674d9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?