Php Slim框架:插入查询问题

Php Slim框架:插入查询问题,php,slim,Php,Slim,我是新来的。我不知道如何在Slim框架中执行插入查询 请有人给我看一个例子或教程,以便更好地理解它。 我已经阅读了Android hive教程,但仍然不清楚 使用高级REST API时,我无法发布参数 生成0响应 下面是我的index.php文件代码: global $name; $app->get('/saveEvent', function() { global $user_id; $response = array(); $db = new DbHandle

我是新来的。我不知道如何在Slim框架中执行插入查询

请有人给我看一个例子或教程,以便更好地理解它。 我已经阅读了Android hive教程,但仍然不清楚

使用高级REST API时,我无法发布参数

生成0响应

下面是我的
index.php
文件代码:

global $name;

$app->get('/saveEvent', function() {
    global $user_id;
    $response = array();
    $db = new DbHandler();
    $name = $app->request->post('name');
    $result = $db->createUser($name);

    //$response["error"] = false;
    if ($result != NULL) {
        $response["error"] = false;
        $response["message"] = "Task created successfully";
    } else {
        $response["error"] = true;
        $response["message"] = "Failed to create task. Please try again";
    }
    echoRespnse(201, $response);
});

$app->run();

以下是如何执行post的示例:

$app->post("/book", function () use($app, $db) {
    $app->response()->header("Content-Type", "application/json");
    $book = $app->request()->post();
    $result = $db->books->insert($book);
    echo json_encode(array("id" => $result["id"]));
});

您使用的是
get
路由,但是您试图检索
POST
ed参数?当我使用POST路由时,它会给出404响应errorAdvance rest api响应是404,当我传递参数时,“advance”是什么意思?请用
post
路线更新您的问题,以显示您的代码。强烈反对使用
globals
。这就像用炸药为你的汽车提供动力。