X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/examples/restful/remote/lib/model.php?ds=inline diff --git a/examples/restful/remote/lib/model.php b/examples/restful/remote/lib/model.php new file mode 100644 index 00000000..cf0ef2f3 --- /dev/null +++ b/examples/restful/remote/lib/model.php @@ -0,0 +1,70 @@ +save(); + return $obj; + } + static function find($id) { + global $dbh; + $found = null; + foreach ($dbh->rs() as $rec) { + if ($rec['id'] == $id) { + $found = new self($rec); + break; + } + } + return $found; + } + static function update($id, $params) { + global $dbh; + $rec = self::find($id); + if ($rec == null) { + return $rec; + } + $rs = $dbh->rs(); + foreach ($rs as $idx => $row) { + if ($row['id'] == $id) { + $rec->attributes = array_merge($rec->attributes, $params); + $dbh->update($idx, $rec->attributes); + break; + } + } + return $rec; + } + static function destroy($id) { + global $dbh; + $rec = null; + $rs = $dbh->rs(); + foreach ($rs as $idx => $row) { + if ($row['id'] == $id) { + $rec = new self($dbh->destroy($idx)); + break; + } + } + return $rec; + } + static function all() { + global $dbh; + return $dbh->rs(); + } + + public function __construct($params) { + $this->id = $params["id"] || null; + $this->attributes = $params; + } + public function save() { + global $dbh; + $this->attributes['id'] = $dbh->pk(); + $dbh->insert($this->attributes); + } + public function to_hash() { + return $this->attributes; + } +} +