diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 0c55948..cc70320 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -433,7 +433,8 @@ abstract class BaseController extends Controller $this->_viewDatas = $this->init(__FUNCTION__); helper(['form']); $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; - $this->_viewDatas['entity'] = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); + $this->_viewDatas['entity'] = $this->view_process($entity); $this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']); return view($this->_viewPath . '/view', $this->_viewDatas); } catch (\Exception $e) { diff --git a/app/Controllers/Front/BoardController.php b/app/Controllers/Front/BoardController.php index 4743f87..c39c341 100644 --- a/app/Controllers/Front/BoardController.php +++ b/app/Controllers/Front/BoardController.php @@ -60,4 +60,11 @@ class BoardController extends FrontController } return $this->_viewDatas['fieldDatas']; } + + //View관련 + protected function view_process($entity) + { + $entity = parent::view_process($entity); + return $this->_model->addViewCount($entity); + } } diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index 4238360..8dcd3e2 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -95,4 +95,11 @@ class BoardModel extends BaseHierarchyModel $this->orLike($this->getTitleField(), $word, "both"); $this->orLike("content", $word, "both"); //befor , after , both } + + //조회수 올리기 + final public function addViewCount(BoardEntity $entity, int $view_cnt = 1): BoardEntity + { + $entity->view_cnt += $view_cnt; + return $this->save_process($entity); + } }