簡體   English   中英

Slim Framework-通過簡單的“ $ request-> get”獲取“ 500 Internal Server Error”

[英]Slim Framework - Getting “500 Internal Server Error” for a simple “$request->get”

我是Slim框架的新手,在一個非常基本的調用$request->get遇到錯誤。

  • 供應/主機-確定
  • 供應/主機/ 28E34748B48E-確定
  • 供應/主機/搜索?主機名= ACACA- NOK


盡管var_dump($_GET)返回:

array(1) {
  ["hostname"]=>
  string(5) "ACACA"
}

index.php文件的內容:

<?php
require 'vendor/autoload.php';

//With default settings
$app = new \Slim\App;

$app->get('/hosts', function ($request,$response,$args) {
        require_once 'db.php';
        $query= "SELECT * FROM hosts";
        $result = $mysqli->query($query);
        while($row=$result->fetch_assoc()) {
                $data[]=$row;
        }
        if(isset($data)) {
                header('Content-Type: application/json');
                echo json_encode($data);
        }
});

$app->get('/hosts/search', function ($request,$response,$args) {
        require_once 'db.php';
        //echo var_dump($_GET);
        $hostname=$request->get('hostname');
        echo $hostname;
});

$app->get('/hosts/{macaddr}', function ($request,$response,$args) {
        require_once 'db.php';
        $query= "SELECT * FROM hosts WHERE macaddr='".$args['macaddr']."'";
        $result = $mysqli->query($query);
        $data=$result->fetch_assoc();
        if(isset($data)) {
                header('Content-Type: application/json');
                echo json_encode($data);
        }
});

$app->run();
?>

方法getSlim\\Http\\Request中不存在

Fatal error: Call to undefined method Slim\Http\Request::get() in /slim3/index.php on line 

您需要使用getParam

$hostname = $request->getParam('hostname');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM