Created
January 4, 2012 19:11
-
-
Save andrewpthorp/1561520 to your computer and use it in GitHub Desktop.
My tiny MVC for PHP
This file contains hidden or 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 | |
// Default Values | |
ini_set('display_errors', 1); | |
// Load Application | |
require 'application/wildfire.php'; | |
?> |
This file contains hidden or 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 | |
/** | |
* This is the Loader, which sets up variables and loads the view. | |
* | |
* @author Andrew Thorp | |
* @copyright F.L.A.S.H 2012 | |
*/ | |
class Load { | |
function view($file_name, $data = null){ | |
if (is_array($data)){ | |
extract($data); | |
} | |
// Load the View | |
include 'views/' . $file_name; | |
} | |
} | |
?> |
This file contains hidden or 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 | |
/** | |
* This is the controller, which brings the model and the view together. | |
* | |
* @author Andrew Thorp | |
* @copyright F.L.A.S.H 2012 | |
*/ | |
class ReportsController { | |
public $load; | |
public $model; | |
function __construct(){ | |
$this->load = new Load(); | |
$this->model = new Report(); | |
} | |
public function index(){ | |
$this->load->view( 'reports/index.php' ); | |
} | |
// TODO: Implement "CREATE" for this resource | |
public function create($data){ | |
// Create an instance of the model | |
// Redirect to "success.php" | |
} | |
} | |
?> |
This file contains hidden or 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
<!-- Among other things, this form exists --> | |
<form id="new-report" accept-charset="utf-8" method="post"> | |
<input id="new-report-email" name="email" name="email" placeholder="Email Address" /> | |
</form> |
This file contains hidden or 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 | |
// DEFAULTS | |
require 'load.php'; | |
require 'lib/rb.php'; | |
require 'lib/connection.php'; | |
/** | |
* MAGIC autload function. This will get called whenever a class definition | |
* is not present. This is standard wih PHP. | |
* | |
* @author Andrew Thorp | |
* @copyright F.L.A.S.H 2012 | |
*/ | |
function __autoload( $class_name ){ | |
$class = strtolower($class_name); | |
if (strpos($class, 'controller')){ | |
require('controllers/' . $class . '.php'); | |
} | |
else { | |
require('models/' . $class . '.php'); | |
} | |
} | |
$C = new ReportsController(); | |
$C->index(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know how I would implement the create method, because I am using a simple ORM for PHP.
My question is, how would you setup the form in views_reports_index.php to use the create method?