79 lines
2.9 KiB
PHP
79 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
abstract class CommonModel extends Model
|
|
{
|
|
protected $table = '';
|
|
protected $primaryKey = '';
|
|
protected $useAutoIncrement = true;
|
|
// protected $returnType = 'array';
|
|
//true이면 모든 delete * 메소드 호출은 실제로 행을 삭제하는 것이 아니라 플래그를 데이터베이스로 설정
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = [];
|
|
|
|
// $allowEmptyInserts = false (기본값): 삽입할 데이터가 전혀 없는 경우, CI4는 오류를 발생시키며 쿼리 실행을 막습니다. (보안 및 데이터 무결성 목적)
|
|
// $allowEmptyInserts = true: 삽입할 데이터가 없어도 INSERT INTO table_name () VALUES () 같은 빈 쿼리 실행을 허용합니다 (극히 드문 경우에 사용).
|
|
protected bool $allowEmptyInserts = false;
|
|
protected bool $updateOnlyChanged = true;
|
|
|
|
// protected $useEmptyStringIfNull = true; (기본값)
|
|
// 이 기본 설정 때문에 PHP의 null 값이 데이터베이스로 전달될 때 실제 SQL의 NULL 키워드가 아닌 **빈 문자열 ('')**로 변환되고 있습니다.
|
|
// 그리고 데이터베이스(MySQL 등)의 설정에 따라 빈 문자열이 업데이트 쿼리에서 무시되거나, 해당 컬럼의 기존 값이 유지되는 현상이 발생합니다.
|
|
protected $useEmptyStringIfNull = false; //NULL값도 넣을려면 false
|
|
|
|
protected array $casts = [];
|
|
protected array $castHandlers = [];
|
|
|
|
// Dates
|
|
protected $useTimestamps = false;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Validation
|
|
protected $validationRules = [];
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
protected $cleanValidationRules = true;
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = []; //Field 값이 NULL일 경우 DB Default값 적용용
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = []; //Field 값이 NULL일 경우 DB Default값 적용용
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
protected function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
final public function getTable(): string
|
|
{
|
|
return constant("static::TABLE");
|
|
}
|
|
final public function getPKField(): string
|
|
{
|
|
return constant("static::PK");
|
|
}
|
|
final public function getTitleField(): string
|
|
{
|
|
return constant("static::TITLE");
|
|
}
|
|
final public function useAutoIncrement(): bool
|
|
{
|
|
return $this->useAutoIncrement;
|
|
}
|
|
final public function getAllowedFields(): array
|
|
{
|
|
return $this->allowedFields;
|
|
}
|
|
}
|