php - Slim Framework - Getting "500 Internal Server Error" for a simple "$request->get" -


i'm new slim framework , i'm getting error in basic call $request->get.

  • provision/hosts - ok
  • provision/hosts/28e34748b48e - ok
  • provision/hosts/search?hostname=acaca - nok


although var_dump($_get) returns:

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

contents of index.php file:

<?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 * 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 * hosts 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(); ?> 

the method get doesn't exist in slim\http\request

fatal error: call undefined method slim\http\request::get() in /slim3/index.php on line  

you need use getparam

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

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -