diff --git a/Model.php b/Model.php index fcb81fb..7a84bd9 100644 --- a/Model.php +++ b/Model.php @@ -559,6 +559,7 @@ public function getTableName() public function insert() { + $this->triggerEvent('creating'); $insert_query = $this->createInsertQuery(); $prepared_query = $this->db_engine->prepare($insert_query); @@ -569,10 +570,13 @@ public function insert() return $prepared_query; } - public function insertFromPost($post) + public function insertFromPost() { - $insert_query = $this->createInsertQueryFromPost($post); - $insert_query->execute(); + $this->triggerEvent('creating'); + $insert_query = $this->createInsertQueryFromPost($_POST); + $insert_query->execute(); + $this->triggerEvent('created'); + return $this; } public function json() @@ -679,14 +683,14 @@ public function storeCache() $this->cache = false; } - private function callEvent($event) + private function callEvent($event, $trigger) { $pos = strrpos($event, "\\"); if ($pos !== false) { - $subject = substr_replace($event, "::", $pos, strlen("\\")); + $subject = $event."::".$trigger; } - $new_instance = new $this; + $new_instance = $this; unset($new_instance->Events); return $subject($new_instance); } @@ -694,8 +698,11 @@ private function callEvent($event) public function triggerEvent($event) { if ($this->Events) { - if (array_key_exists($event, $this->Events)) { - $this->callEvent($this->Events[$event]); + foreach($this->Events as $key => $value){ + if ($key == $event) { + $this->callEvent($this->Events[$event], $key); + return; + } } } }