ADD считаю кол-во переходов по сокращённой ссылке
This commit is contained in:
parent
716e4d394b
commit
90d96afb2b
|
|
@ -318,4 +318,20 @@ abstract class Model
|
||||||
return (int)$row['cnt'];
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ class SController extends Controller
|
||||||
$shortUrl = ShortUrl::model()->getByPK($key);
|
$shortUrl = ShortUrl::model()->getByPK($key);
|
||||||
|
|
||||||
if($shortUrl->id) {
|
if($shortUrl->id) {
|
||||||
|
$shortUrl->update(array('views' => intval($shortUrl->views + 1)));
|
||||||
App::redirect($shortUrl->url);
|
App::redirect($shortUrl->url);
|
||||||
} else {
|
} else {
|
||||||
App::error404();
|
App::error404();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue