addClassPaths('User'); } public function getFormService(): UserForm { if ($this->formServiceInstance === null) { $this->formServiceInstance = new UserForm(); $this->formServiceInstance->setAttributes([ 'pk_field' => $this->model->getPKField(), 'title_field' => $this->model->getTitleField(), 'table' => $this->model->getTable(), 'useAutoIncrement' => $this->model->useAutoIncrement(), 'class_path' => $this->getClassPaths(false) ]); } return $this->formServiceInstance; } public function getHelper(): UserHelper { if ($this->helperInstance === null) { $this->helperInstance = new UserHelper(); $this->helperInstance->setAttributes([ 'pk_field' => $this->model->getPKField(), 'title_field' => $this->model->getTitleField(), 'table' => $this->model->getTable(), 'useAutoIncrement' => $this->model->useAutoIncrement(), 'class_path' => $this->getClassPaths(false) ]); } return $this->helperInstance; } //기본 기능부분 protected function create_process(array $formDatas): UserEntity { if (isset($formDatas['confirmpassword'])) { unset($formDatas['confirmpassword']); } //UserEntity를 생성하면 Setter가 자동 호출됩니다. return new UserEntity($formDatas); } public function create(object $dto): UserEntity { if (!$dto instanceof UserDTO) { throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다."); } return parent::create($dto); } protected function modify_process(CommonEntity $entity, array $formDatas): UserEntity { // CommonEntity 타입을 UserEntity로 형 변환합니다. (타입 힌트가 CommonEntity지만 실제로는 UserEntity 객체입니다.) $userEntity = $entity; if (isset($formDatas['confirmpassword'])) { unset($formDatas['confirmpassword']); } // 변경 사항을 Entity에 적용합니다. (Dirty Tracking 활성화) $userEntity->fill($formDatas); // 💡 부모 호출 제거: 변경된 Entity 객체를 반환합니다. return $userEntity; } public function modify($entity, object $dto): UserEntity { if (!$dto instanceof UserDTO) { throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다."); } return parent::modify($entity, $dto); } //List 검색용 //FormFilter 조건절 처리 public function index_condition_filterField(string $field, mixed $filter_value): void { switch ($field) { case 'role': $where = "FIND_IN_SET(" . $this->model->escape($filter_value) . ", {$this->model->getTable()}.{$field}) > 0"; //FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생합니다. 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동 $this->model->where($where, null, false); break; default: parent::index_condition_filterField($field, $filter_value); break; } } //검색어조건절처리 public function index_condition_filterWord(string $word): void { $this->model->orLike($this->model->getTable() . '.id', $word, 'both'); $this->model->orLike($this->model->getTable() . "." . $this->model->getTitleField(), $word, 'both'); $this->model->orLike($this->model->getTable() . '.email', $word, 'both'); parent::index_condition_filterWord($word); } }