diff options
author | Filipp Lepalaan <filipp@mekanisti.fi> | 2009-10-13 10:42:01 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mekanisti.fi> | 2009-10-13 10:42:01 +0300 |
commit | 08cba850d34f1e3692ec2aa9ff051fdeabe47b7f (patch) | |
tree | bfc77312d1071d2785359e3a8a6067c377668319 | |
parent | b9d2b8467dd4046512b86e0f63feefb6b06c2789 (diff) | |
download | main-08cba850d34f1e3692ec2aa9ff051fdeabe47b7f.tar.gz main-08cba850d34f1e3692ec2aa9ff051fdeabe47b7f.tar.bz2 main-08cba850d34f1e3692ec2aa9ff051fdeabe47b7f.zip |
Some more fixes
-rw-r--r-- | .DS_Store | bin | 6148 -> 0 bytes | |||
-rw-r--r-- | App.php | 6 | ||||
-rw-r--r-- | Controller.php | 28 | ||||
-rw-r--r-- | Db.php | 7 |
4 files changed, 26 insertions, 15 deletions
diff --git a/.DS_Store b/.DS_Store Binary files differdeleted file mode 100644 index d150107..0000000 --- a/.DS_Store +++ /dev/null @@ -25,6 +25,8 @@ class App $controller = "user"; } + ob_start(); + // Dispatch correct controller $c = new $controller; @@ -45,7 +47,9 @@ class App return $c->$action($c); } - exit(App::error("{$controller}_{$action}: no such method")); + App::error("{$controller}_{$action}: no such method"); + + ob_end_flush(); } diff --git a/Controller.php b/Controller.php index 4b16041..8f8bbd8 100644 --- a/Controller.php +++ b/Controller.php @@ -27,6 +27,9 @@ class Controller return $this; } + /** + * Get One Thing + */ public function get($id) { return $this->find(array('id' => $id)); @@ -38,7 +41,7 @@ class Controller public function find($where = null, $sort = false, $limit = false) { $select = "*"; $q = ""; - + // Allow custom queries if (is_array($where)) { @@ -104,24 +107,23 @@ class Controller $sql .= " LIMIT $limit"; } - $stmt = DB::query($sql, $values); - - $i = 0; + $result = DB::query($sql, $values)->fetchAll(PDO::FETCH_ASSOC); - foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) + for ($i=0; $i < count($result); $i++) { + $row = $result[$i]; $this->data[$i] = $row; $this->find_parent($row, $i); $this->find_children($row, $i); - $i++; } - + return $this; } /** - * Return all child rows for this row + * Find all child rows for this row + * @return void */ private function find_children($row, $i) { @@ -152,9 +154,8 @@ class Controller } else if (@in_array ($table, $ref_schema['belongsTo'])) { // 1/m $sql = "SELECT * FROM `$ref` WHERE `$ref`.`{$table}_id` = ?"; } - - $stmt = App::db()->prepare($sql); - $stmt->execute(array($id)); + + $stmt = DB::query($sql, array($id)); $this->data[$i][$child] = $stmt->fetchAll(PDO::FETCH_ASSOC); } @@ -229,7 +230,8 @@ class Controller $insert = ""; $values = array(); - foreach($data as $k => $v) { + foreach($data as $k => $v) + { $insert .= "`{$k}`, "; $values[":{$k}"] = $v; } @@ -237,8 +239,6 @@ class Controller $insert = rtrim($insert, ", "); $val = implode(", ", array_keys($values)); $sql = "INSERT INTO `{$this->table}` ({$insert}) VALUES ({$val})"; - - App::log($sql); return DB::query($sql, $values); @@ -52,6 +52,7 @@ class Db /** * Execute an SQL query + * @return mixed */ public function query($sql, $data = null) { @@ -92,6 +93,12 @@ class Db return $data; } + + public function fetch($sql, $data = null) + { + $stmt = DB::query($sql, $data); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } } |