diff --git a/classes/Model.php b/classes/Model.php index 2e29508..32cbdd2 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -318,4 +318,20 @@ abstract class Model return (int)$row['cnt']; } + function update(array $fields) + { + if (empty($fields)) { + return FALSE; + } + + $request = App::DB()->prepare('UPDATE ' . $this->_tableName_ . ' SET `' . implode('`=?, `', array_keys($fields)) . '`=? WHERE ' . $this->_primaryKey_ . '=' . $this->_id_); + $res = $request->execute(array_values($fields)); + + if ($res) + { + return $this->getByPK($this->_id_); + } + + return FALSE; + } } diff --git a/controllers/SController.php b/controllers/SController.php index d8e9253..2b16617 100644 --- a/controllers/SController.php +++ b/controllers/SController.php @@ -8,6 +8,7 @@ class SController extends Controller $shortUrl = ShortUrl::model()->getByPK($key); if($shortUrl->id) { + $shortUrl->update(array('views' => intval($shortUrl->views + 1))); App::redirect($shortUrl->url); } else { App::error404();