Skip to content

Instantly share code, notes, and snippets.

@travismillerweb
Created August 12, 2012 18:58
Show Gist options
  • Save travismillerweb/3333742 to your computer and use it in GitHub Desktop.
Save travismillerweb/3333742 to your computer and use it in GitHub Desktop.
PHP - Simple MVC
<?php
class Controller
{
public $load;
public $model;
function __construct()
{
$this->load = new Load();
$this->model = new Model();
//determine what page you are one
$this->home();
}
function home()
{
$data = $this->model->user_info();
$this->load->view('someview.php', $data);
}
}
<?php
//Display errors in production mode
ini_set('display_errors', 1);
require 'application/tiny-mvc.php';
?>
<?php
class Load
{
function view ($file_name, $data = null)
{
if (is_array($data))
{
extract($data);
}
include 'views/'.$file_name;
}
}
?>
<?php
class Model
{
public function user_info()
{
//array that simulates real data
return array
(
'first' => 'Travis',
'last' => 'Miller'
);
}
}
<html>
<head>
<title>Simple MVC</title>
</head>
<body>
<h1> Simple MVC</h1>
Hello from the View <?php echo $first .' '.$last.'!'; ?>
</body>
</html>
<?php
require 'load.php';
require 'model.php';
require 'controller.php';
new Controller();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment