使用 REST API 从表中获取数据 [英] fetch data from table using REST API
问题描述
我正在使用 Slim 框架设计 REST api.我正在使用数据库 mySql.我正在用 php 设计这个 API.
I am designing REST api using Slim framework. I am using database mySql. and i am designing this API in php.
我正在尝试从我的表中获取有关学生的数据.
I am trying to fetch data about student from my table.
我正在尝试这样:-
<?php
header('Content-type: application/json');
// Include the Slim library
require 'Slim/Slim.php';
// Instantiate the Slim class
$app = new Slim();
// Create a GET-based route
$app->get('/hello/:name', 'hello');
function hello($name)
{
// here is code to access detail of $name
echo $name
// how can i get detail if i have value of name=:kuntal not name=kuntal
}
// Ready the routes and run the application
$app->run();
?>
我正在使用这个 url 尝试这个功能:-192.168.1.101/hello/:kuntal
I am trying this function using this url:- 192.168.1.101/hello/:kuntal
我需要将名称的值设为 kuntal 但在函数中我将名称的值设为 :kuntal 所以请告诉我如何删除它:(冒号) 在名称之前.
i need to get value of name as kuntal but in function i am getting value of name as :kuntal so please tell me how can i remove this :(colon) before the name.
是另一种方法.
如果您了解用于制作 REST API 的超薄框架,请给我您的建议.提前致谢.
Please give me your suggestion if you are aware about slim framework to make REST API. Thank you in advance.
推荐答案
试试这个网址:192.168.1.101/hello/kuntal我认为这肯定适用于您的代码.
Try this url: 192.168.1.101/hello/kuntal i think this will definitely work for your code.
这篇关于使用 REST API 从表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!