Created
August 12, 2012 18:58
-
-
Save travismillerweb/3333742 to your computer and use it in GitHub Desktop.
PHP - Simple MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Display errors in production mode | |
ini_set('display_errors', 1); | |
require 'application/tiny-mvc.php'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Load | |
{ | |
function view ($file_name, $data = null) | |
{ | |
if (is_array($data)) | |
{ | |
extract($data); | |
} | |
include 'views/'.$file_name; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Model | |
{ | |
public function user_info() | |
{ | |
//array that simulates real data | |
return array | |
( | |
'first' => 'Travis', | |
'last' => 'Miller' | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Simple MVC</title> | |
</head> | |
<body> | |
<h1> Simple MVC</h1> | |
Hello from the View <?php echo $first .' '.$last.'!'; ?> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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