How to write interfaces for php

Source: Internet
Author: User
: This article describes how to write interfaces for php. For more information about PHP tutorials, see. I have been writing my website for a year. I have been writing PC-end websites. recently I changed my company to have an APP business, which involves interface problems, so I found some materials and wrote some project interfaces. while I remembered them, I wrote them down and looked at them later.

The APP interface itself is not difficult, just like writing a common website, but the value assigned to the HTML page in the controller becomes an interface for outputting json data. the following code is used:

Public function jiekou () {// query $ User = M ('user'); $ list = $ User-> select (); // query data $ return ['list'] = $ list; echojson ($ return); // json data returned by the interface}
Public function delall () // delete {$ User = M ('user'); $ map ['id'] = 1; if ($ User-> where ($ map) -> delete () {$ return ['code'] = 200; $ return ['MSG '] = 'deleted successfully'; echojson ($ return );} else {$ return ['code'] = 400; $ return ['MSG '] = 'deletion failed'; echojson ($ return );}}

Of course, I also see a lot of output formats, such as echo json_encode ($ return. The test tool uses Postman of the Google plug-in. you can find it in the Google app store. if you cannot open the app store, you can download a Google hosts file from the Internet, update on the local computer.

The above describes how to write interfaces in php, including some content, and hope to help those who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.