Feedback on my basic MVC

Hi,

I’m trying to learn the MVC programming pattern for the web and have put together a basic MVC pattern and was wondering if you fine people would mind taking a look over it to see A, whether I’ve done it right and B, whether there are any improvements I could do to make it more flexible etc.

Whilst trying to get my head around MVC I took a look at Code Igniter and noticed that their base controller (called CI_Controller) is a singleton pattern. Whilst learning MVC I’d like to do it without the use of a Singleton pattern but I can see it getting pretty confusing without using the Singleton pattern, does anyone have any suggestions about this?

One thing to realise whilst looking over the code is as this is my first attempt you might see things (such as hardcoding view paths, instantiating models manually) that I will be improving upon as I get my head further into MVC.

URL: /index.php?controller=home

index.php



$FrontController = new FrontController($_GET['controller'], $_GET['model'], $_GET['action']);

echo $FrontController->siteHeader();

echo $FrontController->getContents();

echo $FrontController->siteFooter();


FontController.php


class FrontController {

	protected $_Controller;
	protected $_Load;
	private $_contents;
	
	public function __construct($controller, $model = NULL, $action = NULL) {
		
		$this->_Load = new Load();
		
		if (class_exists($controller, false)) {
			
			$this->_Controller = new $controller($this->_Load);

			if (empty($action)) {
				$action = 'index';
			}

			if (method_exists($this->_Controller, $action)) {
				$this->_contents = $this->_Controller->{$action}();
			}
		
		} else {
			$this->_contents = 'Class \\'' . $controller . '\\' does not exist...';
		}

	}
	
	public function siteHeader() {

		return $this->_Load->view('views/header.php');

	}
	
	public function siteFooter() {
		
		return $this->_Load->view('views/footer.php');

	}
	
	public function getContents() {
		return $this->_contents;	
	}
	
}

Load.php


class Load {

	public function view($file_name, array $var = null) {

		ob_start();
	
		include($file_name);
		
		$this->_viewOutput = ob_get_contents();
	
		ob_end_clean();
		
		unset($var);
		
		return $this->_viewOutput;

	}

}

HomeModel.php


class ModelHome {

	public function getHomeData() {
		
		/* Naturally this will do all of the necessary database reading/writing, but below is some example data */
		
		return array(
			'title' => 'Welcome to a test MVC Framework',
			'desc'  => 'This is a learning experience of model/view/controller programming pattern.'
		);
	}

}

HomeView.php


<h1><?php echo $var['title']; ?></h1>
<p><?php echo $var['desc']; ?></p>

HomeController.php


class Home {

	private $_Load;
	private $_Model;

	public function __construct(Load $_Load) {

		$this->_Load = $_Load;
		$this->_Model = new ModelHome();

	}

	public function index() {
		
		$data = $this->_Model->getHomeData();

		return $this->_Load->view('application/views/home.php', $data);

	}

}

you should look how i have implemented mine in opencart.com.

its ridiculosity simple and gets straight to the point of how MVC should be implemented.