I've been writing procedurally for several years now and recently I decided to make the leap to Object Orientated code.
To help me get on the right footing I've been working on an MVC framework of my own. I'm aware of Zend and so forth, but I just want something elegant and lightweight where I understand everything 100% and can build up knowledge. However, I need a little help and advice.
Basic folder architecture is:
/view/
/controller/
/model/
index
.htaccess
These are the files I have so far:
/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z]*)/?(.*)?$ index.php?controller=$1&path=$2 [NC,L]
/index.php
//autoload new classes
function __autoload($class)
{
$folder = explode('_', $class);
require_once strtolower(str_replace('_', '/', $class)).'_'.$folder[0].'.php';
}
//instantiate controller
if (!isset($_GET['controller'])) { $_GET['controller'] = 'landing'; }
$controller_name = 'controller_'.$_GET['controller'];
new $controller_name($_GET,$_POST);
/controller/base_controller.php
abstract class controller_base
{
//store headers
protected $get;
protected $post;
//store layers
protected $view;
protected $model;
protected function __construct($get,$post)
{
//store the header arrays
$this->get = $get;
$this->post = $post;
//preset the view layer as an array
$this->view = array();
}
public function __destruct()
{
//extract variables from the view layer
extract($this->view);
//render the view to the user
require_once('view/'.$this->get['controller'].'_view.php');
}
}
/controller/landing_controller.php
class controller_landing extends controller_base
{
public function __construct($get,$post)
{
parent::__construct($get,$post);
//simple test of passing some variables to the view layer
$this->view['text1'] = 'some different ';
$this->view['text2'] = 'bit of text';
}
}
Question 1) Is this framework laid out correctly?
Question 2) How should I integrate the model layer into this framework?
Question 3) Any other suggestions about how to improve this?