Home > Backend Development > PHP Tutorial > API background processing of tp5

API background processing of tp5

零下一度
Release: 2023-03-10 18:08:02
Original
4603 people have browsed it

This article is a summary of the company's API interface backend!

1. Naming precautions:

Do not use confusing names, such as index, index01...

I like to use pinyin...

For example:

 public function zhuce(Request $request)
Copy after login

2. Database file modification:

Go to database.php and remove the prefix of the data;

3. Get the requested value:

$data = input();$uid = $uid['uid'];    //获取uid
$tel = $data['tel'];   //获取电话号码
$pwd = $data['password'];//获取输入的密码
$macaddress = $data['macaddress'];//获取mac地址
Copy after login

4. Operation database:

(1) Native operation:

 $mi = Db::query("select password from users where uid= {$uid}");
Copy after login

(2) name query:

  $users = Db::name('users')->where('uid','=', $uid)//条件->select();
Copy after login

5 .Return JSON array:

    //       返回json数组  $aa = array('code' =>$code,
            'msg' => array(             'users'=>$users),);
Copy after login

Output:

  echo json_encode($aa,256);
Copy after login

256 is to prevent garbled characters;

The above is the detailed content of API background processing of tp5. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template