From cefb0b6a3fb6ea45b1f65e1dc0e453616667480e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0git=20config=20git=20config=20-?= =?UTF-8?q?-helpgit=20config=20--global=20user=2Ename=20=EC=B5=9C=EC=A4=80?= =?UTF-8?q?=ED=9D=A0?= Date: Thu, 3 Aug 2023 04:37:51 +0900 Subject: [PATCH] servermgrv2 init... --- app/Controllers/Admin/UserController.php | 2 +- app/Controllers/BaseController.php | 7 +++++++ app/Models/BaseModel.php | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index e15d814..bcb5816 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -68,7 +68,7 @@ class UserController extends AdminController foreach ($this->_viewDatas['fieldRules'] as $field => $rule) { switch ($field) { case 'role': - $rules['role.*'] = $rule; + $rules[$field . '.*'] = $rule; break; default: $rules[$field] = $rule; diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 36cb928..4546c26 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -50,6 +50,7 @@ abstract class BaseController extends Controller */ protected $_model = null; protected $_session = null; + protected $_validation = null; protected $_viewPath = ''; protected $_viewDatas = array(); public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) @@ -59,6 +60,7 @@ abstract class BaseController extends Controller // Preload any models, libraries, etc, here. // E.g.: $this->session = \Config\Services::session(); $this->_session = \Config\Services::session(); + $this->_validation = \Config\Services::validation(); $this->_viewDatas['layout'] = LAYOUTS['empty']; $this->_viewDatas['session'] = $this->_session; } @@ -199,6 +201,11 @@ abstract class BaseController extends Controller protected function update_validate($entity) { //fieldData Rule 검사 + //추후 VersionUP용 + // $this->_model->getValidation($this->getFields()); + // if (! $this->_validation->run($user)) { + // throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors())); + // } if (!$this->validate($this->_viewDatas['fieldRules'])) { throw new \Exception("{$this->_viewDatas['title']}의 검증 오류발생\n" . implode("\n", $this->validator->getErrors())); } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index f57d605..64051aa 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -43,6 +43,7 @@ abstract class BaseModel extends Model private $_user_options = null; private $_className = null; protected $_session = null; + protected $_validation = null; protected function __construct(string $className) { $this->_className = $className; @@ -53,6 +54,7 @@ abstract class BaseModel extends Model } $this->validationRules = []; $this->_session = \Config\Services::session(); + $this->_validation = \Config\Services::validation(); } final public function getClassName() { @@ -114,6 +116,19 @@ abstract class BaseModel extends Model } return $rules; } + //추후 VersionUP용 + final public function getValidation(array $fields, string $action = "") + { + $this->_validation->reset(); + foreach ($fields as $field) { + $this->_validation->setRule( + $field, + lang($this->getClassName() . '.label.' . $field), + $this->getValidationFieldRule($field, $action) + ); + } + return $this->_validation; + } //Field별 Form Option용 public function getOptions(array $conditions = array(), $options = array()): array {