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

View File

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