aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.DS_Storebin6148 -> 0 bytes
-rw-r--r--App.php6
-rw-r--r--Controller.php28
-rw-r--r--Db.php7
4 files changed, 26 insertions, 15 deletions
diff --git a/.DS_Store b/.DS_Store
deleted file mode 100644
index d150107..0000000
--- a/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/App.php b/App.php
index 442ca8c..89dda01 100644
--- a/App.php
+++ b/App.php
@@ -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);
diff --git a/Db.php b/Db.php
index 7d85d0d..2ce5ff0 100644
--- a/Db.php
+++ b/Db.php
@@ -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);
+ }
}