Asked  7 Months ago    Answers:  2   Viewed   45 times
require 'Slim/Slim.php';
use SlimSlim;

$app = new SlimSlim();

require_once 'item.php';

this is code excerpt from index.php and stuck on the said error when it called item.php. Here the contains of the file

$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 hit the error on this $app = Slim::getInstance();

What is wrong with my approach?



The Slim class' full name (including namespace) is SlimSlim so you'll need to use that, eg

$app = SlimSlim::getInstance();

Alternatively, you can import the Slim symbol using the use statement at the top of your item.php script.

use SlimSlim;
Wednesday, March 31, 2021
answered 7 Months ago

What exactly causes this error?

  • class SlimSlim no longer exists

instead of getting request from statically shared instance, use one which is passed as first argument to your addJob function

function addJob(MessageInterface $request) {
    $job = json_decode($request->getBody());
Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :