From c217e77f2540085922b4483c99670eca06923799 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Mon, 26 Oct 2009 15:41:40 +0200 Subject: Bug fixes --- App.php | 31 ++++++++++++++++--------------- Controller.php | 9 +++++++-- Db.php | 12 +++++------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/App.php b/App.php index e1428d4..c8b93cf 100644 --- a/App.php +++ b/App.php @@ -21,8 +21,6 @@ class App if (empty($param)) { $action = "index"; } - -// $conf['basedir'] = dirname(dirname(__FILE__) . "/system"); if (!$controller) { $controller = "user"; @@ -81,10 +79,11 @@ class App static function type() { - $last = array_pop(explode("/", @$_GET['url'])); + $tokens = explode("/", $_SERVER['REQUEST_URI']); + $last = array_pop($tokens); $type = ltrim(strrchr($last, "."), "."); - $contentTypes = array('html', 'rss', 'xml', 'tpl', 'pdf', 'jpg'); + $contentTypes = array("html", "rss", "xml", "tpl", "pdf", "jpg"); if (in_array($type, $contentTypes)) { return $type; @@ -94,14 +93,6 @@ class App } - static function json($msg) - { - $json = json_encode($msg); - header("Content-Type: application/json"); - header("Content-Length: " . strlen($json)); - print $json; - } - static function ok($msg) { $ok = array('result' => 'ok', 'msg' => $msg); @@ -114,7 +105,15 @@ class App self::json($msg); self::log($msg); } - + + static function json($msg) + { + $json = json_encode($msg); + header("Content-Type: application/json"); + header("Content-Length: " . strlen($json)); + print $json; + } + /** * Log an error to our own logging system */ @@ -123,19 +122,21 @@ class App if (is_array($msg)) { $msg = print_r($msg, true); } + $c = self::conf("app.error_log"); $file = realpath(__FILE__."/../../../../data/$c"); if (!$file) { return false; } + $fh = fopen($file, "a+"); - fwrite($fh, $msg); + fwrite($fh, trim($msg) . "\n"); fclose($fh); } static function error_handler($errno, $errstr, $errfile, $errline) { - $str = sprintf("%s\t%s\t%s\t%s\n", date("d.m @ H:i:s"), basename($errfile), $errline, $errstr); + $str = sprintf("%s\t%s\t%s\t%s\n", date("d.m H:i:s"), basename($errfile), $errline, $errstr); self::log($str); } diff --git a/Controller.php b/Controller.php index 8f8bbd8..6ab61df 100644 --- a/Controller.php +++ b/Controller.php @@ -35,6 +35,11 @@ class Controller return $this->find(array('id' => $id)); } + public function db() + { + return Db::getInstance(); + } + /** * The New Find */ @@ -107,7 +112,7 @@ class Controller $sql .= " LIMIT $limit"; } - $result = DB::query($sql, $values)->fetchAll(PDO::FETCH_ASSOC); + $result = Db::fetch($sql, $values); for ($i=0; $i < count($result); $i++) { @@ -292,7 +297,7 @@ class Controller $sql = "UPDATE `{$this->table}` SET $query WHERE `$col` = :$col"; - return DB::query($sql, $values); + return Db::query($sql, $values); } diff --git a/Db.php b/Db.php index f72ba4b..4e5fe8a 100644 --- a/Db.php +++ b/Db.php @@ -22,8 +22,7 @@ class Db { $c = App::conf(); - if (!self::$instance) - { + if (!self::$instance) { try { self::$instance = new PDO( "{$c['db.driver']}:host={$c['db.host']};dbname={$c['db.name']}", @@ -47,7 +46,7 @@ class Db */ public function __clone() { - trigger_error("Hello, ich name was Singleton. Cloning is not allowed", E_USER_ERROR); + trigger_error("Cloning not work is", E_USER_ERROR); } /** @@ -72,13 +71,12 @@ class Db if (!$result) { $e = $stmt->errorInfo(); - exit(App::error($e[2])); + App::error($e[2]); } } catch (PDOException $e) { $error = $e->getMessage() . $sql; - App::log($error); - exit(App::error($error)); + App::error($error); } // Select statements need the query results @@ -96,7 +94,7 @@ class Db public function fetch($sql, $data = null) { - $stmt = DB::query($sql, $data); + $stmt = self::query($sql, $data); return $stmt->fetchAll(PDO::FETCH_ASSOC); } -- cgit v1.2.3