First of all ... Do no put autoloading script in routing mechanism. You are mixing the responsibilities. You will be better off creating a separate class for this based on spl_autoload_register.
Neeext .. do no put complicated operations on constructor. It is makes you code somewhat untestable. Maybe you should be something like:
// you might want to replace $_GET with $_SERVER['QUERY_STRING'] later $router = new Router( $_GET['url'] ); // where 'default' is the name of fallback controller $controller_class = $router->get_controller( 'default' ); $method_name = $router->get_action( 'index' ); $model_factory = new ModelFactory( new PDO( ... ) ); $controller = new {$controller_class}( $model_factory ); $controller->{$method_name}();
Additionally, you should look into php namespaces. There is no point in ending class with ...Controller just to know where the class will be located.
Ok ... back to the Model.
There is quite common misconception about models in web development community ( i blame RoR for this mess ). Model in MVC is not a class, but an application layer which contains multitude of instances. Most of the instances belong to one of two types of classes. With following responsibilities:
Domain Logic :
Deals with all the computation, calculation and all the domain specific details. Objects in this group have no knowledge of where and how data is actually stored. They only manipulate the information.
Data Access
Usually made of objects that fit DataMapper pattern (do not confuse with ORM of same name .. nothing in common). Responsible for storing data from Domain Objects and retrieving them. Might be in database.. might not. This is where your SQL queries would be.
In semi-real world situation () it might looks something like this (related to code abowe):
class SomeController { // ... snip ... protected $model_factory = null; // ... snip ... public function __construct( ModelFactory $factory ) { $this->model_factory = $factory; } // ... snip ... public function action_foobar() { $user = $this->model_factory->build_object( 'User' ); $mapper = $this->model_factory->build_mapper( 'User' ); $user->set_id(42); $mapper->fetch($user); if ( $user->hasWarning() ) { $user->set_status( 'locked' ); } $mapper->store( $user ); } // ... snip ... }
As you see, there is no indication how the data was stored. It does not even matter if user account was new, or already existing.
Some materials you might find useful
Videos
Books: