SlimMVC is the easiest and flexible way to create your PHP application using a MVC pattern. SlimMVC use the PHP microframework Slim Framework and use the best practices collected in the slim community.
Here we have the core classes of the connection with the DB
Add the model classes here. We are using PDO for the Database.
Example of class:
Stuff.php
class Stuff {
protected $core;
function __construct() {
$this->core = Core::getInstance();
}
// Get all stuff
public function getAllStuff() {
$r = array();
$sql = "SELECT * FROM stuff";
$stmt = $this->core->dbh->prepare($sql);
if ($stmt->execute()) {
$r = $stmt->fetchAll(\PDO::FETCH_ASSOC);
} else {
$r = 0;
}
return $r;
}
}
All the public files:
All the files with the routes. Each file contents the routes of an specific functionality. It is very important that the names of the files inside this folder follow this pattern: name.router.php
Example of router file:
stuff.router.php
// Get stuff
$app->get('/stuff', function () use ($app) {
echo 'This is a GET route';
});
//Create user
$app->post('/stuff', function () use ($app) {
echo 'This is a POST route';
});
// PUT route
$app->put('/stuff', function () {
echo 'This is a PUT route';
});
// DELETE route
$app->delete('/stuff', function () {
echo 'This is a DELETE route';
});
All the Twig templates.