From 633a3497b5de6f5c89b6a2c309354fa8d5992ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 8 Aug 2023 11:45:28 +0900 Subject: [PATCH] shoppingmallv2 init... --- app/Controllers/Front/BoardController.php | 4 +++ app/Models/BaseModel.php | 38 ++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/Controllers/Front/BoardController.php b/app/Controllers/Front/BoardController.php index fbf5434..ab6463d 100644 --- a/app/Controllers/Front/BoardController.php +++ b/app/Controllers/Front/BoardController.php @@ -95,7 +95,11 @@ class BoardController extends FrontController //권한체크 $this->isRole('view', $entity); //조회수 올리기 + echo var_export($entity, true); + echo "
"; $entity = $this->_model->addViewCount($entity); + echo var_export($entity, true); + exit; return parent::view_process($entity); } //Index관련 diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 1a14ba6..9fb964c 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -77,6 +77,7 @@ abstract class BaseModel extends Model { switch ($field) { case $this->primaryKey: + //수동입력인경우 if (!$this->useAutoIncrement) { $rules[$field] = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]"; $rules[$field] .= $action == "insert" ? "|is_unique[{$this->table}.{$field}]" : ""; @@ -183,13 +184,6 @@ abstract class BaseModel extends Model protected function changeFormData(string $action, string $field, array $formDatas, $entity) { switch ($field) { - case $this->primaryKey: - //primaryKey가 자동입력이 아니면 - if (!$this->useAutoIncrement) { - $pk = $this->primaryKey; - $entity->$pk = $this->getUUID(); - } - break; case "user_uid": //입력데이터로 있을시 관리툴에서 (사용자,등)추가, 없을시는 입력의 경우에만 자동(장바구니,등)으로 추가 if (array_key_exists($field, $formDatas)) { //관리툴 USERSNS에서 사용자 연동 시 추가기능등에 사용 @@ -219,7 +213,7 @@ abstract class BaseModel extends Model return $entity; } - final protected function save_process($entity) + final protected function save_process($entity): BaseEntity { // echo var_export($entity, true); // exit; @@ -229,28 +223,30 @@ abstract class BaseModel extends Model log_message("error", implode("\n", $this->errors())); throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . $this->getLastQuery() . "\n" . var_export($this->errors(), true)); } - //primaryKey가 자동입력이면 - if ($this->useAutoIncrement) { - $pk = $this->primaryKey; - $entity->$pk = $this->insertID(); - } } else { throw new \Exception(__FUNCTION__ . " 오류 발생.\n 기존정보와 동일하여 수정되지 않았습니다."); } return $entity; } - protected function create_process($entity, array $formDatas) + protected function create_process($entity, array $formDatas): BaseEntity { - // echo var_export($entity); - // exit; - foreach ($this->allowedFields as $field) { + foreach ($this->formDatas as $field => $value) { $entity = $this->changeFormData('create', $field, $formDatas, $entity); } - // echo var_export($this->allowedFields); - // exit - return $this->save_process($entity); + //primaryKey가 수동입력이면 + if (!$this->useAutoIncrement) { + $pk = $this->primaryKey; + $entity->$pk = $this->getUUID(); + } + $entity = $this->save_process($entity); + //primaryKey가 자동입력이면 + if ($this->useAutoIncrement) { + $pk = $this->primaryKey; + $entity->$pk = $this->insertID(); + } + return $entity; } - final protected function modify_process($entity, array $formDatas) + final protected function modify_process($entity, array $formDatas): BaseEntity { foreach ($this->allowedFields as $field) { if ($field != $this->primaryKey) {