I am trying slim for the first time and I liked the concept of micro frameworks. I love the fact that I can manage my own database layer rather than relying on ORMs, so rest apart I am stuck adding my own classes in slim app. I went through Slim docs and it was not that much clear what should I use to add my own classes in the app. I am using Middleware for now and this is how I am trying to implement.
Directory structure
Index file:
<?php
require 'Slim\Slim.php' ;
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->add(new \models\MyDb());
$app->config(array(
'templates.path' => 'templates',
));
$app->get('/', function() use ($app){
$data = $db->testApp();
$app->render('main.php', $data);
});
$app->run();
?>
my database wrapper that I would like to implement:
models/db.php
class MyDb extends ..\Slim\Middleware{
public function testApp(){
/* Returns something */
}
}
Error that is returned
Fatal error: Class 'models\MyDb' not found in C:\xampp\htdocs\slimtest\index.php on line 6
I know I am making really simple mistake or I am over thinking the implementation but kindly explain in detail as I am fairly new to Slim and Micro framework in general.
I have went through these questions on stack-overflow:
hooks versus middleware in slim 2.0
Routing with AngularJS and Slim PHP
but they were not of that much help plus I don't like going with procedural way and to write all logic in one file.
Note: I have tried replacing slashes and directory structure but no luck.