/** * Удаление комментария * * @param $id */ public function deleteAction($id) { $id = (int) $id; $adapter = MVC\Application::getAdapter(); $result = $adapter->fetchOne("SELECT count(*) as `count` FROM `comment` WHERE `parent_id` = {$id}"); if ($result and (int) $result['count'] > 0) { $this->render('comment/delete.twig', array('success' => false, 'url' => $_SERVER['HTTP_REFERER'])); } else { $repository = $this->getRepository('Comment'); $repository->deleteById($id); $this->redirect($_SERVER['HTTP_REFERER']); } }
/** * Удаление сущности */ public function delete() { // Если метода нет он попадёт в __call $this->beforeDelete(); $table = $this->getTableName(); $query = "DELETE FROM `{$table}` WHERE `id` = {$this->id};"; $res = App::getAdapter()->query($query); $this->afterDelete(); return $res; }
/** * @param $sql * @return array */ public function findBySql($sql) { $adapter = MVC\Application::getAdapter(); $result = $adapter->query($sql); if ($result && mysql_num_rows($result)) { return $this->mapResult($result); } return $result ? array() : $result; }