There is a class that describes a row of the BaseModel table. BaseModel has many heirs for each table in the database (for example: OrderModel ).
The base model has a delete method that looks like this:
/** * This function should be overriden if needed * @return boolean(true|false) */ public function beforeDelete() { return true; } /** * This function should be overriden if needed * @return boolean(true|false) */ public function afterDelete() { return true; } /** * Remove record from DB * @throws UnexpectedValueException when trying to remove record with unknown id or id < 0 * @throws RuntimeException if afterDelete() didn't work properly * @return boolean(true|false) * * @uses Database::exec() * @uses $this->beforeDelete() * @uses $this->afterDelete() */ public function delete() { if (empty($this->id) || $this->id < 0) { throw new UnexpectedValueException('Can`t delete record with unset ID in '.__CLASS__. ', see file '.__FILE__.' at line '.__LINE__); } if ($this->beforeDelete()) { $sql = 'DELETE FROM `'.static::$tableName.'` WHERE `'.static::$fields['id'].'`=:'.static::$fields['id']; $pdoArgs = array(); $pdoArgs[] = array('param' => ':'.static::$fields['id'], 'arg' => $this->id, 'type' => static::$pdoTypes[static::$fieldTypes['id']]); if (Database::getInstance()->exec($sql, $pdoArgs)) { if ($this->afterDelete()) { return true; } else { throw new RuntimeException('Model has been deleted but afterDelete() don`t work correct, class '.__CLASS__. ', see file '.__FILE__.' at line '.__LINE__); } } } return false; } Interested in how to delete a class object in the afterDelete() method, since the model remains available and you can call the save() method for it, etc.
Example: let's say we have a list of orders, I go around it with foreach-ем and delete unacknowledged models (by calling the method ->delete() ), and then I launch another foreach to send orders ->send() . But in the list everything will still be objects that are deleted. How to make for them the right unset.
unsetunnecessary models in the collection - Naumovunset($this);methodunset($this);and in my collection will appearnull. - Makarenko_I_V