public function save() { $data = ['id' => $this->id, 'title' => $this->title, 'content' => $this->content, 'user_id' => $this->user_id, 'comment_count' => $this->getCommentCount(), 'updated_at' => date(MYSQL_DATE_TIME)]; $db = DB::instance(); $this->id = $db->store($data, self::$table); return $this->id; }
public function save() { $post = PostModel::get($this->post_id); $data = ['id' => $this->id, 'post_id' => $this->post_id, 'user_id' => $this->user_id, 'name' => $this->name, 'message' => $this->message, 'updated_at' => date(MYSQL_DATE_TIME)]; $db = DB::instance(); $this->id = $db->store($data, self::$table); $post->comment_count = self::getCommentCount($post); $post->save(); return $this->id; }
public static function authorize($email, $password) { Validate::length($email, 1, null, "Заполните поле Email"); Validate::length($password, 1, null, "Заполните поле Пароль"); $db = DB::instance(); $query = $db->getQuery(); $query->select("*")->from(self::$table)->where("email = '%s'", $email)->where("password = '******'", md5($password)); $user = $db->queryRow($query); Validate::check(!empty($user), "Неверный логин или пароль"); $_SESSION['user']['id'] = $user['id']; return new self($user); }
public function delete() { $db = DB::instance(); $db->delete(static::$table, "id = '{$this->id}'"); }