Skip to content

Instantly share code, notes, and snippets.

@andrewpthorp
Created January 4, 2012 19:11
Show Gist options
  • Save andrewpthorp/1561520 to your computer and use it in GitHub Desktop.
Save andrewpthorp/1561520 to your computer and use it in GitHub Desktop.
My tiny MVC for PHP
<?php
// Default Values
ini_set('display_errors', 1);
// Load Application
require 'application/wildfire.php';
?>
<?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;
}
}
?>
<?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"
}
}
?>
<!-- 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>
<?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();
?>
@andrewpthorp
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment