From 90d96afb2b9b5ba7025af5e910277f0aae479f29 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Thu, 5 May 2016 23:52:42 +0300 Subject: [PATCH] =?UTF-8?q?ADD=20=D1=81=D1=87=D0=B8=D1=82=D0=B0=D1=8E=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB-=D0=B2=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=D0=BE=D0=B2=20=D0=BF=D0=BE=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BA=D1=80=D0=B0=D1=89=D1=91=D0=BD=D0=BD=D0=BE=D0=B9=20=D1=81?= =?UTF-8?q?=D1=81=D1=8B=D0=BB=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/Model.php | 16 ++++++++++++++++ controllers/SController.php | 1 + 2 files changed, 17 insertions(+) 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();