0

This is an excerpt of my index.php I have composer installed but I keep getting class sim not found.

<?php
require '../vendor/autoload.php';
$app = new \Slim\Slim(array(
    'templates.path' => '../templates'
));

$app->get('/api', function () use ($app) {
    // Get the start and end timestamps from request query parameters
    $startTimestamp = $app->request->get('start');
    $endTimestamp = $app->request->get('end');

    try {
        // Open database connection
        $conn = new \PDO('mysql:host=127.0.0.1;dbname=calendar', 'root', '');

        // Query database for events in range
        $stmt = $conn->prepare('SELECT * FROM events WHERE start >= FROM_UNIXTIME(:start) AND end < FROM_UNIXTIME(:end) ORDER BY start ASC');
        $stmt->bindParam(':start', $startTimestamp, \PDO::PARAM_INT);
        $stmt->bindParam(':end', $endTimestamp, \PDO::PARAM_INT);
        $stmt->execute();

        // Fetch query results 
        $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);

        // Return query results as JSON
        echo json_encode($results);
    } catch (\PDOException $e) {
        $app->halt(500, $e->getMessage());
   }
});
$app->get('/', function () use ($app) {
    $app->render('calendar.html');
});
$app->run();
?>

What am I doing wrong? I am trying to implement the Full Calendar jquery plugin

1
  • This is caused by a typo. The class name is \Slim\App not \Slim\Slim
    – Nima
    Nov 15, 2018 at 6:22

1 Answer 1

0

1 - You could verify your installed packages composer info -i

2 - Peraps you make a tipo new \Slim\Slim

Try

$app = new \Slim\App(array(
    'templates.path' => '../templates'
));
3
  • slim\slim is installed. Worked when I used \App. But now I'm getting "Slim Application Error" "A website error has occurred. Sorry for the temporary inconvenience." How do i find out whats causing this error?
    – Allan
    Nov 10, 2018 at 20:53
  • I don't know this framwork but I take a look to the documentation: your code look like version 2 of the framwork and you certenly have a version 3 installed
    – acucchieri
    Nov 10, 2018 at 21:36
  • Thank you. I ended up using version 2 and the site worked.
    – Allan
    Nov 11, 2018 at 18:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.