doufei2194 2016-04-01 19:42
浏览 61

类Slim \ Http \ Request的对象无法转换为double

I'm trying to send a friendship request, combining users ids in one table, but seems i have made somewhere a mistake. Here is the fragment of code:

public function sendRequest($user_one_id, $user_two_id, $status, $action_user_id) {
    $stmt = $this->conn->prepare("INSERT INTO relationship(user_one_id, user_two_id, status, action_user_id) VALUES (?, ?, ?, ?)");
    $stmt->bind_param("iiii", $user_one_id, $user_two_id, $status, $action_user_id);
    $result = $stmt->execute(); // HERE IS AN ERROR
    $stmt->close();

    if (!$result) {
        return NULL;
    } else {
        return TRUE;
    }
}

The error i'm getting:

Object of class Slim\Http\Request could not be converted to double

EDIT:

This is how i'm calling method:

$app->post('/send_request', function() use ($app) {

// check for required params
verifyRequiredParams(array('user_one_id', 'user_two_id', 'status', 'action_user_id'));

// reading post params
$user_one_id = $app->request('user_one_id');
$user_two_id = $app->request('user_two_id');
$status = $app->request('status');
$action_user_id = $app->request('action_user_id');
$response = array();

$db = new DbHandler();

$relationship = $db->sendRequest($user_one_id, $user_two_id, $status, $action_user_id);

if ($relationship != NULL) {
    $response["error"] = false;
    $response["request"]["user_one_id"] = $relationship["user_one_id"];
    $response["request"]["user_two_id"] = $relationship["user_two_id"];
    $response["request"]["status"] = $relationship["status"];
    $response["request"]["action_user_id"] = $relationship["action_user_id"];
} else {
    $response["error"] = true;
    $response["message"] = "An error occurred. Please try again later.";
}
echoRespnse(200, $response);
});
  • 写回答

1条回答 默认 最新

  • douzhang6176 2016-04-01 22:36
    关注

    What happens in your verifyRequiredParams function? In the code you posted I dont see any conversion of a Slim\Http\Request object.

    $user_one_id = $app->request('user_one_id');
    $user_two_id = $app->request('user_two_id');
    $status = $app->request('status');
    $action_user_id = $app->request('action_user_id');
    

    From what I can tell, these are the only lines of code where you do anything with a Slim request object. Can you verify that the values in these variables you are setting are correct? Like var_dump() them and put an exit in your code and see what it says.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号