Various small improvements

This commit is contained in:
Timothy Warren 2012-01-08 16:07:54 -05:00
parent 42ffdd0ad9
commit 2d85763af6
3 changed files with 66 additions and 38 deletions

View File

@ -205,37 +205,37 @@ class db extends PDO {
// --------------------------------------------------------------------------
/**
* Returns the last error from the database
*
* @return string
*/
function get_last_error()
{
$error = array();
if(isset($this->statement))
{
$error = $this->statement->errorInfo();
}
else
{
$error = $this->errorInfo();
}
$code = $error[0];
$driver_code = $error[1];
$message = $error[2];
// Contain the content for buffering
/**
* Returns the last error from the database
*
* @return string
*/
function get_last_error()
{
$error = array();
if(isset($this->statement))
{
$error = $this->statement->errorInfo();
}
else
{
$error = $this->errorInfo();
}
$code = $error[0];
$driver_code = $error[1];
$message = $error[2];
// Contain the content for buffering
ob_start();
include(APP_PATH.'/errors/error_db.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
}
}
// End of db.php

View File

@ -266,6 +266,21 @@ class miniMVC extends JSObject{
unset($this->$name);
}
}
/**
* Convenience function to load config files
*
* @param string $name
*/
function load_config($name)
{
$path = APP_PATH . "config/{$name}.php";
if(is_file($path))
{
require_once($path);
}
}
}
// --------------------------------------------------------------------------

View File

@ -1,20 +1,18 @@
<?php
/**
* Class for content output
*/
class Output extends miniMVC {
private $buffer, $headers;
function __construct()
{
// Compression is good!
ob_start("ob_gzhandler");
$this->buffer = "";
$this->headers = array();
}
// --------------------------------------------------------------------------
/**
* PHP magic method called when ending the script
* Used for outputing HTML
@ -40,14 +38,11 @@ class Output extends miniMVC {
if( ! empty($this->buffer))
{
ob_start("ob_gzhandler");
echo $this->buffer;
ob_end_flush();
}
}
// --------------------------------------------------------------------------
/**
* Sets a header for later output
* @param string $key
@ -58,8 +53,6 @@ class Output extends miniMVC {
$this->headers[$key] = $val;
}
// --------------------------------------------------------------------------
/**
* Adds text to the output buffer
*
@ -70,8 +63,6 @@ class Output extends miniMVC {
$this->buffer .= $string;
}
// --------------------------------------------------------------------------
/**
* Sets the output buffer
*
@ -81,6 +72,28 @@ class Output extends miniMVC {
{
$this->buffer = $string;
}
/**
* Sends headers and then removes them
*/
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