Simplify framework classes, add some category functionality

This commit is contained in:
Timothy Warren 2012-06-14 16:33:16 -04:00
parent 054ea4f908
commit 4125c033fc
22 changed files with 595 additions and 512 deletions

View File

@ -22,16 +22,6 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/*
|--------------------------------------------------------------------------
| Display Debug backtrace
|--------------------------------------------------------------------------
|
| If set to TRUE, a backtrace will be displayed along with php errors.
|
*/
define('SHOW_DEBUG_BACKTRACE', TRUE);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Base Url | Base Url

View File

@ -35,6 +35,9 @@ return array(
'default_module' => 'meta', 'default_module' => 'meta',
'genre' => 'meta/genre/index', 'genre' => 'meta/genre/index',
'genre/add' => 'meta/genre/add', 'genre/add' => 'meta/genre/add',
'category' => 'meta/category/index',
'category/add' => 'meta/category/add',
'category/detail' => 'meta/category/detail',
'404_route' => '', '404_route' => '',
); );

View File

@ -0,0 +1,93 @@
<?php
/**
* meta
*
* Hierarchial data tool
*
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Category controller
*
* @package meta
*/
class Category extends miniMVC\Controller {
/**
* Initialize the Controller
*/
public function __construct()
{
parent::__construct();
$this->load_model('meta\model');
$this->page->build_header();
}
/**
* Default controller method
*/
public function index()
{
$id = (int) miniMVC\get_last_segment();
if ($id === 0)
{
return miniMVC\show_404();
}
$this->detail();
}
/**
* Adds a new category
*/
public function add()
{
// Strip away tags for the sake of security
$name = strip_tags($_POST['category']);
$id = (int) $_POST['genre_id'];
// Make sure the name doesn't already exist. If it does, show an error.
$res = $this->model->add_category($name, $id);
if ($res === TRUE)
{
$this->page->set_message('success', 'Added new category');
}
else
{
$this->page->set_message('error', 'Category already exists for this genre');
}
// Render the basic page
$this->index();
}
/**
* Returns the sections / editing options for a category
*/
public function detail()
{
$id = (int) miniMVC\get_last_segment();
$data = array(
'category' => $this->model->get_category_by_id($id),
'sections' => $this->model->get_sections($id),
'category_id' => $id
);
$this->load_view('category_detail', $data);
$this->page->build_footer();
}
}
// End of genre.php

View File

@ -0,0 +1,30 @@
<?php
/**
* meta
*
* Hierarchial data tool
*
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Section Controller
*/
class Section extends \miniMVC\Controller {
/**
* Constructor
*/
public function __construct()
{
}
}
// End of section.php

View File

@ -50,6 +50,9 @@ class Welcome extends miniMVC\Controller {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Authenticate a user
*/
public function login() public function login()
{ {

View File

@ -138,12 +138,30 @@ class Model extends \miniMVC\Model {
* *
* @param string * @param string
* @param int * @param int
* @return bool
*/ */
public function add_category($cat, $genre_id) public function add_category($cat, $genre_id)
{
// Check for duplicates
$query = $this->db->from('category')
->where('genre_id', $genre_id)
->where('category', $cat)
->get();
// Fetch the data as a workaround
// for databases that do not support
// grabbing result counts (SQLite / Firebird)
$array = $query->fetchAll();
if (count($array) === 0)
{ {
$this->db->set('category', $cat) $this->db->set('category', $cat)
->set('genre_id', $genre_id) ->set('genre_id', $genre_id)
->insert('category'); ->insert('category');
return TRUE;
}
return FALSE;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -253,6 +271,8 @@ class Model extends \miniMVC\Model {
return $genres; return $genres;
} }
// --------------------------------------------------------------------------
/** /**
* Gets the name of the genre from its id * Gets the name of the genre from its id
* *
@ -273,6 +293,46 @@ class Model extends \miniMVC\Model {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Gets the name of the category from its id
*
* @param int
* @return string
*/
public function get_category_by_id($id)
{
$query = $this->db->select('category')
->from('category')
->where('id', (int) $id)
->get();
$row = $query->fetch(\PDO::FETCH_ASSOC);
return $row['category'];
}
// --------------------------------------------------------------------------
/**
* Gets the name of the section from its id
*
* @param int
* @return string
*/
public function get_section_by_id($id)
{
$query = $this->db->select('section')
->from('section')
->where('id', (int) $id)
->get();
$row = $query->fetch(\PDO::FETCH_ASSOC);
return $row['section'];
}
// --------------------------------------------------------------------------
/** /**
* Get the categories for the specified genre * Get the categories for the specified genre
* *

View File

@ -22,6 +22,9 @@ namespace meta;
*/ */
class User_model extends \miniMVC\Model { class User_model extends \miniMVC\Model {
/**
* Initialize the User model
*/
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();

View File

@ -0,0 +1,23 @@
<h1>meta</h1>
<h3><?= $category ?></h3>
<h4>Category Sections</h4>
<ul class="list">
<?php foreach($sections as $id => $section): ?>
<li><a href="<?= miniMVC\site_url("section/detail/{$id}") ?>"><?= $section ?></a></li>
<?php endforeach ?>
</ul>
<form action="<?= miniMVC\site_url("section/add") ?>" method="post">
<fieldset>
<lengend>Add Section</lengend>
<dl>
<!-- Weird tag wrapping is intentional for display: inline-block -->
<dt><label for="section">Section name:</label></dt><dd>
<input type="text" name="section" id="section" /></dd>
<dt><input type="hidden" name="category_id" value="<?= $category_id ?>" /></dt><dd>
<button type="submit">Add Section</button></dd>
</dl>
</fieldset>
</form>

View File

@ -4,7 +4,7 @@
<h4>Genre Categories</h4> <h4>Genre Categories</h4>
<ul class="list"> <ul class="list">
<?php foreach($categories as $id => $cat): ?> <?php foreach($categories as $id => $cat): ?>
<li><a href="<?= miniMVC\site_url("category/{$id}") ?>"><?= $cat ?></a></li> <li><a href="<?= miniMVC\site_url("category/detail/{$id}") ?>"><?= $cat ?></a></li>
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>

View File

@ -0,0 +1,15 @@
<h1>meta</h1>
<h3>Login</h3>
<form action="<?= miniMVC\site_url('welcome/login') ?>" method="post">
<dl>
<dt><label for="user">Username:</label></dt>
<dd><input type="text" id="user" name="user" /></dd>
<dt><label for="pass">Password:</label></dt>
<dd><input type="password" id="pass" name="pass" /></dd>
<dt>&nbsp;</dt>
<dd><button type="submit">Login</button></dd>
</dl>
</form>

View File

@ -8,6 +8,14 @@ html, body {
margin: 0 auto; margin: 0 auto;
} }
a {
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
/* form styles */ /* form styles */
form dt, form dd { form dt, form dd {
display:inline-block; display:inline-block;

View File

@ -24,19 +24,7 @@
namespace miniMVC; namespace miniMVC;
// Set as either DEVELOPMENT or PRODUCTION error_reporting(-1);
// DEVELOPMENT enables error reporting
// PRODUCTION disables error reporting
define('ENVIRONMENT', 'DEVELOPMENT');
if(ENVIRONMENT == 'DEVELOPMENT')
{
error_reporting(-1);
}
else if(ENVIRONMENT == 'PRODUCTION')
{
error_reporting(0);
}
// Set the default paths // Set the default paths
define('MM_BASE_PATH', __DIR__); define('MM_BASE_PATH', __DIR__);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<phpdoc> <phpdoc>
<title>miniMVC</title> <title>meta</title>
<parser> <parser>
<target>docs</target> <target>docs</target>
</parser> </parser>
@ -16,11 +16,12 @@
<directory>assets</directory> <directory>assets</directory>
<directory>app/config</directory> <directory>app/config</directory>
<directory>app/views</directory> <directory>app/views</directory>
<directory>sys/db/tests</directory> <directory>sys/db</directory>
<ignore>tests/*</ignore> <ignore>tests/*</ignore>
<ignore>assets/*</ignore> <ignore>assets/*</ignore>
<ignore>sys/db/tests/*</ignore> <ignore>sys/db/*</ignore>
<ignore>app/config/*</ignore> <ignore>app/config/*</ignore>
<ignore>app/views/*</ignore> <ignore>app/views/*</ignore>
<ignore>*/views/*</ignore>
</files> </files>
</phpdoc> </phpdoc>

View File

@ -79,7 +79,7 @@ function shutdown()
$error = error_get_last(); $error = error_get_last();
// types of errors that are fatal // types of errors that are fatal
$fatal = [E_ERROR, E_PARSE, E_RECOVERABLE_ERROR]; $fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
// Display pretty error page // Display pretty error page
if (in_array($error['type'], $fatal)) if (in_array($error['type'], $fatal))
@ -308,6 +308,9 @@ function init()
// Load Database classes // Load Database classes
require_once(MM_SYS_PATH . 'db/autoload.php'); require_once(MM_SYS_PATH . 'db/autoload.php');
// Load the page class
$GLOBALS['page'] = new \miniMVC\Page();
// Map to the appropriate module/controller/function // Map to the appropriate module/controller/function
route(); route();
} }
@ -327,6 +330,40 @@ function get_last_segment()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Call a method in another controller
*
* @param string
* @param string
* @param args
*/
function call_controller_method($controller, $method="index", $args=array())
{
// Load the routes config file
$routes = include(MM_APP_PATH . 'config/routes.php');
// Set the default route
$module = $routes['default_module'];
$class = $routes['default_controller'];
// Split the controller into module/controller if possible
$parts = explode('/', $controller);
if (count($parts) === 2)
{
list($module, $class) = $parts;
}
else
{
$class = $parts[0];
}
// Call the method
run($module, $class, $method, $args);
}
// --------------------------------------------------------------------------
/** /**
* Gets an array of the segments of the current url * Gets an array of the segments of the current url
* *
@ -463,14 +500,17 @@ function route()
return; return;
} }
// --------------------------------------------------------------------------
/** /**
* Instantiate the appropriate controller * Instantiate the appropriate controller
* *
* @param string * @param string
* @param string * @param string
* @param string * @param string
* @param array
*/ */
function run($module, $controller, $func) function run($module, $controller, $func, $args = array())
{ {
$path = MM_MOD_PATH . "{$module}/controllers/{$controller}.php"; $path = MM_MOD_PATH . "{$module}/controllers/{$controller}.php";
@ -484,10 +524,13 @@ function run($module, $controller, $func)
if (in_array($func, $methods)) if (in_array($func, $methods))
{ {
// Define the name of the current module for file loading // Define the name of the current module for file loading
if ( ! defined('MM_MOD'))
{
define('MM_MOD', $module); define('MM_MOD', $module);
}
$class = new $controller(); $class = new $controller();
return call_user_func([&$class, $func]); return call_user_func_array(array(&$class, $func), $args);
} }
} }
@ -495,5 +538,4 @@ function run($module, $controller, $func)
show_404(); show_404();
} }
// End of common.php // End of common.php

View File

@ -21,7 +21,7 @@ namespace miniMVC;
* @package miniMVC * @package miniMVC
* @subpackage System * @subpackage System
*/ */
class Controller extends miniMVC { class Controller {
/** /**
* Instance of Page class * Instance of Page class
@ -37,10 +37,8 @@ class Controller extends miniMVC {
*/ */
public function __construct() public function __construct()
{ {
parent::__construct();
// Create the page object // Create the page object
$this->page = new Page($this); $this->page = $GLOBALS['page'];
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -52,7 +50,7 @@ class Controller extends miniMVC {
* @param array $args * @param array $args
* @return void * @return void
*/ */
public function load_model($file, $args=[]) public function load_model($file, $args=array())
{ {
$segments = explode('\\', $file); $segments = explode('\\', $file);
$file_name = end($segments); $file_name = end($segments);
@ -87,41 +85,9 @@ class Controller extends miniMVC {
* @param bool $return * @param bool $return
* @return mixed * @return mixed
*/ */
public function load_view($file, array $data=[], $return=FALSE) public function load_view($file, array $data=array(), $return=FALSE)
{ {
$path = ""; return $this->page->load_view($file, $data, $return);
// The module is set via the router
$module = strtolower(MM_MOD);
$path = MM_MOD_PATH . "{$module}/views/{$file}.php";
// If it's not a module, or doesn't exist in the module view folder
// look in the app view folder
if ( ! is_file($path))
{
$path = MM_APP_PATH . "views/{$file}.php";
}
// Contain the content for buffering
ob_start();
// Extract the data array
extract($data);
// Include the file
include($path);
$buffer = ob_get_contents();
ob_end_clean();
if ($return == TRUE)
{
return $buffer;
}
else
{
$this->page->append_output($buffer);
}
} }
} }

View File

@ -1,70 +0,0 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
/**
* Class for standalone JSObject objects
*
* @package miniMVC
* @subpackage System
*/
class MM extends \ArrayObject {
/**
* Create the ArrayObject hybrid object
*
* @param array
*/
public function __construct($members = array())
{
parent::__construct($members);
// Add the passed parameters to the object
foreach ($members as $name => &$value)
{
$this->$name = $value;
}
}
// --------------------------------------------------------------------------
/**
* Allow calling of array methods on the object and
* dynamic methods
*
* @param string $name
* @param array $params
* @return mixed
*/
public function __call($name, $params = array())
{
// Allow array operations on the object
if (substr($name, 0, 6) === 'array_' && is_callable($name))
{
$args = array_merge($this->getArrayCopy(), $args);
return call_user_func_array($name, $args);
}
// Allow dynamic method calls
if (is_callable($this->$name))
{
//Call the dynamic function
return call_user_func_array($this->$name, $params);
}
}
}
// End of MM.php

View File

@ -21,7 +21,7 @@ namespace miniMVC;
* @package miniMVC * @package miniMVC
* @subpackage System * @subpackage System
*/ */
class Model extends miniMVC { class Model extends \ArrayObject {
/** /**
* Initialize the model class * Initialize the model class
@ -31,7 +31,7 @@ class Model extends miniMVC {
*/ */
public function __construct(array $args = array()) public function __construct(array $args = array())
{ {
parent::__construct($args); parent::__construct($args, \ArrayObject::STD_PROP_LIST | \ArrayObject::ARRAY_AS_PROPS);
} }
} }

View File

@ -1,156 +0,0 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
/**
* Class for displaying output and setting http headers
*
* @package miniMVC
* @subpackage System
*/
class Output extends MM {
/**
* Content for outputting
*
* @var string
*/
private $buffer;
/**
* HTTP headers to send
*
* @var array
*/
private $headers;
/**
* Initialize the output class
*
* @return void
*/
public function __construct()
{
$this->buffer = "";
$this->headers = array();
}
// --------------------------------------------------------------------------
/**
* PHP magic method called when ending the script
* Used for outputing HTML
*
* @return void
*/
public function __destruct()
{
if ( ! empty($this->headers))
{
// Set headers
foreach($this->headers as $key => $val)
{
if ( ! isset($val))
{
@header($key);
}
else
{
@header("$key: $val");
}
}
}
if ( ! empty($this->buffer))
{
if (is_null(error_get_last()))
{
// Compression is good!
ob_start("ob_gzhandler");
}
else
{
ob_start();
}
echo $this->buffer;
ob_end_flush();
}
}
// --------------------------------------------------------------------------
/**
* Sets a header for later output
*
* @param string $key
* @param string $val
*/
public function set_header($key, $val)
{
$this->headers[$key] = $val;
}
// --------------------------------------------------------------------------
/**
* Adds text to the output buffer
*
* @param string $string
*/
public function append_output($string)
{
$this->buffer .= $string;
}
// --------------------------------------------------------------------------
/**
* Sets the output buffer
*
* @param string $string
*/
public function set_output($string)
{
$this->buffer = $string;
}
// --------------------------------------------------------------------------
/**
* Sends headers and then removes them
*/
public function flush_headers()
{
// Set headers
foreach ($this->headers as $key => &$val)
{
if ( ! isset($val))
{
@header($key);
}
else
{
@header("{$key}: {$val}");
}
}
// Empty headers
$this->headers = array();
}
}
// End of Output.php

View File

@ -24,7 +24,7 @@ namespace miniMVC;
* @package miniMVC * @package miniMVC
* @subpackage System * @subpackage System
*/ */
class Page extends Output { class Page {
/** /**
* Meta tags * Meta tags
@ -89,13 +89,26 @@ class Page extends Output {
*/ */
private $base; private $base;
/**
* Content for outputting
*
* @var string
*/
private $buffer;
/**
* HTTP headers to send
*
* @var array
*/
private $headers;
/** /**
* Set up the page class * Set up the page class
* *
* @param object
* @return void * @return void
*/ */
public function __construct(&$controller) public function __construct()
{ {
$this->meta = ""; $this->meta = "";
$this->head_js = ""; $this->head_js = "";
@ -106,19 +119,66 @@ class Page extends Output {
$this->body_class = ""; $this->body_class = "";
$this->body_id = ""; $this->body_id = "";
$this->base = ""; $this->base = "";
$this->buffer = "";
$this->mm = $controller; $this->headers = array();
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* call the parent destructor * PHP magic method called when ending the script
* Used for outputing HTML
*
* @return void
*/ */
public function __destruct() public function __destruct()
{ {
parent::__destruct(); if ( ! empty($this->headers))
{
// Set headers
foreach($this->headers as $key => $val)
{
if ( ! isset($val))
{
@header($key);
} }
else
{
@header("$key: $val");
}
}
}
if ( ! empty($this->buffer))
{
$errors = error_get_last();
if (empty($errors))
{
// Compression is good!
ob_start("ob_gzhandler");
}
else
{
ob_start();
}
echo $this->buffer;
// Check if a buffer exists
// so that it doesn't throw a notice
if (ob_get_level > 0)
{
ob_end_flush();
}
}
else
{
echo 'No content';
}
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -210,11 +270,11 @@ class Page extends Output {
*/ */
public function set_css_group($group) public function set_css_group($group)
{ {
$link = [ $link = array(
'href' => STYLE_PATH . $group, 'href' => STYLE_PATH . $group,
'rel' => 'stylesheet', 'rel' => 'stylesheet',
'type' => 'text/css' 'type' => 'text/css'
]; );
$this->css .= $this->_link_tag($link); $this->css .= $this->_link_tag($link);
return $this; return $this;
@ -316,12 +376,12 @@ class Page extends Output {
$css_file = $name; $css_file = $name;
} }
$this->css_tags .= $this->_link_tag([ $this->css_tags .= $this->_link_tag(array(
'rel' => 'stylesheet', 'rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
'media' => $media, 'media' => $media,
'href' => $css_file, 'href' => $css_file,
]); ));
return $this; return $this;
} }
@ -355,10 +415,10 @@ class Page extends Output {
//Set Meta Tags //Set Meta Tags
$this->meta = ($html5 == TRUE) $this->meta = ($html5 == TRUE)
? '<meta charset="utf-8" />'. $this->meta ? '<meta charset="utf-8" />'. $this->meta
: $this->_meta([ : $this->_meta(array(
'http-equiv' => 'Content-Type', 'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=utf-8', 'content' => 'text/html; charset=utf-8',
]) . $this->meta; )) . $this->meta;
$data['meta'] = $this->meta; $data['meta'] = $this->meta;
@ -396,7 +456,7 @@ class Page extends Output {
$this->_headers($html5); $this->_headers($html5);
//Output Header //Output Header
$this->mm->load_view('header', $data); $this->load_view('header', $data);
return $this; return $this;
} }
@ -412,7 +472,7 @@ class Page extends Output {
$data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : ''; $data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : '';
$this->mm->load_view('footer', $data); $this->load_view('footer', $data);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -457,7 +517,7 @@ class Page extends Output {
$data['stat_class'] = $type; $data['stat_class'] = $type;
$data['message'] = $message; $data['message'] = $message;
return $this->mm->load_view('message', $data, $return); return $this->load_view('message', $data, $return);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -468,7 +528,7 @@ class Page extends Output {
* Shortcut function for 303 redirect * Shortcut function for 303 redirect
* @param string $url * @param string $url
*/ */
function redirect_303($url) public function redirect_303($url)
{ {
$this->set_header("HTTP/1.1 303 See Other"); $this->set_header("HTTP/1.1 303 See Other");
$this->set_header("Location:" . $url); $this->set_header("Location:" . $url);
@ -483,10 +543,10 @@ class Page extends Output {
* @param string $view * @param string $view
* @param array $data * @param array $data
*/ */
function render($view, $data=array()) public function render($view, $data=array())
{ {
$this->build_header(); $this->build_header();
$this->mm->load_view($view, $data); $this->load_view($view, $data);
$this->build_footer(); $this->build_footer();
} }
@ -500,7 +560,7 @@ class Page extends Output {
* page. * page.
* @param string $string * @param string $string
*/ */
function output_string($string) public function output_string($string)
{ {
$this->build_header(); $this->build_header();
$this->append_output($string); $this->append_output($string);
@ -550,6 +610,114 @@ class Page extends Output {
return $string; return $string;
} }
// --------------------------------------------------------------------------
/**
* Function for loading a view
*
* @param string $file
* @param array $data
* @param bool $return
* @return mixed
*/
public function load_view($file, array $data=array(), $return=FALSE)
{
$path = "";
// The module is set via the router
$module = strtolower(MM_MOD);
$path = MM_MOD_PATH . "{$module}/views/{$file}.php";
// If it's not a module, or doesn't exist in the module view folder
// look in the app view folder
if ( ! is_file($path))
{
$path = MM_APP_PATH . "views/{$file}.php";
}
// Contain the content for buffering
ob_start();
// Extract the data array
extract($data);
// Include the file
include($path);
$buffer = ob_get_contents();
ob_end_clean();
if ($return == TRUE)
{
return $buffer;
}
else
{
$this->append_output($buffer);
}
}
// --------------------------------------------------------------------------
/**
* Sets a header for later output
*
* @param string $key
* @param string $val
*/
public function set_header($key, $val)
{
$this->headers[$key] = $val;
}
// --------------------------------------------------------------------------
/**
* Adds text to the output buffer
*
* @param string $string
*/
public function append_output($string)
{
$this->buffer .= $string;
}
// --------------------------------------------------------------------------
/**
* Sets the output buffer
*
* @param string $string
*/
public function set_output($string)
{
$this->buffer = $string;
}
// --------------------------------------------------------------------------
/**
* Sends headers and then removes them
*/
public function flush_headers()
{
// Set headers
foreach ($this->headers as $key => &$val)
{
if ( ! isset($val))
{
@header($key);
}
else
{
@header("{$key}: {$val}");
}
}
// Empty headers
$this->headers = array();
}
} }
// End of page.php // End of page.php

View File

@ -1,84 +0,0 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/aviat4ion/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace miniMVC;
/**
* Base class for the framework
*
* @package miniMVC
* @subpackage System
*/
class miniMVC extends MM {
/**
* Constructor - Any classes loaded here become subclasses of miniMVC
*
* @param array $members
*/
public function __construct($members = array())
{
// Allow the class to be used like an array
parent::__construct($members);
}
// --------------------------------------------------------------------------
/**
* Convenience function to load config files
*
* @param string $name
*/
public function load_config($name)
{
$path = MM_APP_PATH . "config/{$name}.php";
if (is_file($path))
{
require_once($path);
}
}
// --------------------------------------------------------------------------
/**
* Singleton getter function
*
* @return self
*/
public static function &get_instance()
{
if ( ! isset(self::$instance))
{
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
// --------------------------------------------------------------------------
/**
* Magic function called when cloning an object
*/
public function __clone()
{
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
}
// End of miniMVC.php

Binary file not shown.