From bbe9d1a4e30f7c261c00fcb71dd255304d31963d Mon Sep 17 00:00:00 2001 From: Joseph Mancuso Date: Sat, 12 Aug 2017 22:57:15 -0400 Subject: [PATCH] fixed all notice errors inside models --- Model.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Model.php b/Model.php index 5a9de21..ebe2a0c 100644 --- a/Model.php +++ b/Model.php @@ -21,6 +21,8 @@ public function __construct($default_database = null) $this->database = $default_database; } + $this->database_connected = false; + if (method_exists($this, 'create')) { $this->create = true; $this->createDatabaseIfNotExists(); @@ -75,7 +77,7 @@ public function createTable() $keys = explode(":", $value); $query_string .= " DATETIME NOT NULL"; - if ($keys[1]) { + if (isset($keys[1])) { $query_string .= " DEFAULT $keys[1]"; } } elseif (preg_match('/^date/', $value)) { @@ -167,9 +169,9 @@ private function updateForeignKey($tablecolumn, $key, $value) $keys = explode(':', $value); $table = $this->getTableName(); $create_columns = $this->getClassCreateVariables(); - $drop_foreign_key .= " + $drop_foreign_key = " ALTER TABLE $table DROP - FOREIGN KEY `$keys[1]"._."$keys[2]_fk`"; + FOREIGN KEY `$keys[1]"."_"."$keys[2]_fk`"; if ($tablecolumn) { $alter_column = " @@ -239,6 +241,8 @@ private function getClassCreateVariables() unset($allClassProperties['lastrow']); unset($allClassProperties['update']); unset($allClassProperties['last_query']); + unset($allClassProperties['structure']); + unset($defaultClassProperties['structure']); return array_diff($allClassProperties, $defaultClassProperties); } @@ -530,7 +534,8 @@ public function getTableName() return strtolower(end(explode("\\", static::class))); } } else { - return strtolower(end(explode("\\", static::class))); + $explode_namespace = explode("\\", static::class); + return strtolower(end($explode_namespace)); } } @@ -685,7 +690,7 @@ private function callEvent($event, $trigger) public function triggerEvent($event) { - if ($this->Events) { + if (isset($this->Events)) { foreach($this->Events as $key => $value){ if ($key == $event) { $this->callEvent($this->Events[$event], $key); @@ -827,6 +832,7 @@ public function updateFromPost($post, $where_clause = 1) { $this->triggerEvent('updating'); $this->makeDatabaseConnection(); + $values = ""; foreach ($post as $key => $value) { $values .= "`".$key."` = '".$value."',"; } @@ -835,7 +841,6 @@ public function updateFromPost($post, $where_clause = 1) $val = rtrim($val, ","); $table = $this->getTableName(); - $query = $this->db_engine->query("UPDATE `$table` SET $val WHERE $where_clause LIMIT 1"); return $query; }