From 71eebcefb57763451d3cc2749d2ed9e181887157 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sun, 8 Nov 2009 23:35:59 +0200 Subject: Lots of fixes, better url parsing --- Controller.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'Controller.php') diff --git a/Controller.php b/Controller.php index 43b0efe..5432673 100644 --- a/Controller.php +++ b/Controller.php @@ -14,15 +14,19 @@ class Controller const OrderBy = ""; const HasMany = ""; + const TableName = ""; const ManyToMany = ""; const ForeignKey = ""; - const TableName = ""; const TableSelect = ""; function __construct($id = null) { // Child classes should always have the same name as their tables - $this->table = strtolower(get_class($this)); + $this->class = get_class($this); + $this->table = eval("return {$this->class}::TableName;"); + if (!$this->table) { + $this->table = strtolower($this->class); + } $this->result = null; if ($id) { return $this->get($id); @@ -88,10 +92,10 @@ class Controller // $this->schema = $schema[$this->table]; // Ugly hack until PHP 5.3 - $i_sort = eval("return {$this->table}::OrderBy;"); - $i_fk = eval("return {$this->table}::ForeignKey;"); - $i_mtm = eval("return {$this->table}::ManyToMany;"); - $i_select = eval("return {$this->table}::TableSelect;"); + $i_sort = eval("return {$this->class}::OrderBy;"); + $i_fk = eval("return {$this->class}::ForeignKey;"); + $i_mtm = eval("return {$this->class}::ManyToMany;"); + $i_select = eval("return {$this->class}::TableSelect;"); // $orderBy = ($sort) ? $sort : @@ -122,7 +126,7 @@ class Controller $row = $result[$i]; $this->data[$i] = $row; $this->find_parent($row, $i); - $this->find_children($row, $i); +// $this->find_children($row, $i); } return $this; @@ -136,7 +140,7 @@ class Controller private function find_children($row, $i) { $id = $row['id']; // ID of the parent - $fk = explode(",", eval("return $this->table::HasMany;")); + $fk = explode(",", eval("return $this->class::HasMany;")); if (empty($fk[0])) { return false; @@ -175,7 +179,7 @@ class Controller private function find_parent($row, $i) { $select = "*"; - $fk = explode(",", eval("return {$this->table}::ForeignKey;")); + $fk = explode(",", eval("return {$this->class}::ForeignKey;")); // No parents defined if (empty($fk[0])) { -- cgit v1.2.3