1. Create functions.php
app/Common/(目录自己起名字)
Create a new filefunctions.php
below and add the following code inside:
<? php /* * data return * Return json data, prompt for information * @param $status status * @param string $message prompt message * @param array $data return data */ function showMsg($status,$message = '',$data = array()){ $result = array( 'status' => $status, 'message' =>$message, 'data' =>$data ); exit(json_encode($result)); }
2. Configuration composer.json
- Open the file in the project root directory
composer.json
, find the"autoload"
configuration item, and add the following code:
"files":[ "app/Common/functions.php"
]
Screenshot below:
3. Execute the composer
command
- Open a terminal and execute the following command:
#composer dump-autoload
Screenshot below:
4. Test
- Execute the following code in any method of the controller, if there is data output, the configuration is successful:
showMsg(1,'Hello World!');
参考:https://blog.csdn.net/wen_3370/article/details/79599340