Joke Collection Website - Public benefit messages - How to use PHP's CodeIgniter framework to write API interfaces

How to use PHP's CodeIgniter framework to write API interfaces

1. Put the extracted framework package in the www/api directory of your php environment: here, set up the api directory as the test project directory. And run localhost/api/index.php, and you can see the environment interface

2. Modify the method in the controller in the corresponding directory: it is in the application/controller/welcome.php file by default

3. Modify the index method in welcome.php. The welcome page you see is loaded from here

4. Start writing the api interface. Before writing the api interface, link our database. The configuration database information is in application/config/database.php

5. Connect the configured database. Go back to our welcome.php

6. Go to github official website to download the api interface package supported by codeIgniter

7. Unzip the file package and put the corresponding file in the specified directory

8. Modify the method name of the controller and change the index to index_get.

9. Run the interface in the browser and return different data according to different parameters.

json data

localhost/api/index/php? Username= Zhang San&; Format=json

xml data is obtained

localhost/api/index/php? Username= Zhang San&; format=xml