db = $db; $this->table = $table; if (isset($_SESSION['sys']['login'])) $this->username = $_SESSION['sys']['login']; if ($id) { if ($column) $this->loadByColumn($id, $column); else $this->load($id); } } protected function postLoad() {} protected function load($id) { $sql = sprintf("SELECT * FROM %s WHERE %s = %d LIMIT 1", $this->table, $this->idcolumn, $id); $this->data = $this->db->fetchObject($sql); if ($this->data) { $idcolumn = $this->idcolumn; $this->id = $this->data->$idcolumn; $this->postLoad(); return true; } return false; } protected function loadByColumn($id,$column) { $sql = sprintf("SELECT * FROM %s WHERE `%s` = %s", $this->table, $column, $this->db->quote($id)); $this->data = $this->db->fetchObject($sql); if ($this->data) { $idcolumn = $this->idcolumn; $this->id = $this->data->$idcolumn; $this->postLoad(); } } public function id() { return $this->id; } public function get($name) { if (array_key_exists($name, $this->data)) return $this->data->$name; return NULL; } }