aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--App.php27
-rw-r--r--Controller.php9
-rw-r--r--Db.php4
3 files changed, 23 insertions, 17 deletions
diff --git a/App.php b/App.php
index 9912b31..32191a0 100644
--- a/App.php
+++ b/App.php
@@ -81,10 +81,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 +95,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);
@@ -116,7 +109,15 @@ class App
// And log it locally
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
*/
@@ -139,7 +140,7 @@ class App
}
$fh = fopen($file, "a+");
- fwrite($fh, $msg);
+ fwrite($fh, trim($msg) . "\n");
fclose($fh);
}
@@ -148,7 +149,7 @@ class App
*/
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 d5813a1..84947b0 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 e453955..d80071a 100644
--- a/Db.php
+++ b/Db.php
@@ -47,7 +47,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);
}
/**
@@ -106,7 +106,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);
}