session_start(); date_default_timezone_set('GMT'); require 'Slim/Slim.php'; use Slim\Slim; \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); require_once 'item.php';
This is a piece of code from index.php and sticks to the indicated error when it is called item.php . This file contains
$app->put('/getItem', authorize(), 'getItem'); function getItem() { $sql = "SELECT * FROM item"; $app = Slim::getInstance(); try { $db = getConnection(); $stmt = $db->query($sql); $item = $stmt->fetchAll(PDO::FETCH_OBJ); $db = null; $response = $app->response(); $response->header('Content-Type', 'application/json'); // Include support for JSONP requests if (!isset($_GET['callback'])) { echo json_encode($item); } else { echo $_GET['callback'] . '(' . json_encode($item) . ');'; } } catch(PDOException $e) { $error = array("error"=> array("text"=>$e->getMessage())); echo json_encode($error); } }
i will hit the error on this $app = Slim::getInstance();
What is wrong with my approach?
rest php slim
Muhaimin
source share