cfmgrv4/app/Controllers/Admin/UserController.php
2025-03-13 11:25:45 +09:00

62 lines
2.1 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\Helpers\UserHelper;
use App\Services\UserService;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface;
class UserController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->title = lang("{$this->getService()->getClassPath()}.title");
$this->helper = new UserHelper();
}
protected function getService(): UserService
{
if ($this->service === null) {
$this->service = new UserService();
$this->class_name = $this->service->getClassName();
$this->class_path = $this->service->getClassPath();
}
return $this->service;
}
protected function setValidation(string $action, string $field, Validation $validation): Validation
{
switch ($field) {
case 'role':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $this->getService()->getModel()->getFieldRule($action, $field));
break;
default:
$validation = parent::setValidation($action, $field, $validation);
break;
}
return $validation;
}
//생성
protected function create_init(string $action, $fields = []): void
{
$fields = [
'fields' => ['id', 'passwd', 'confirmpassword', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role'],
];
parent::create_init($action, fields: $fields);
}
//수정
protected function modify_init(string $action, $fields = []): void
{
$fields = [
'fields' => ['id', 'passwd', 'confirmpassword', $this->getService()->getModel()::TITLE, 'email', 'mobile', 'role', 'status'],
];
parent::modify_init($action, $fields);
}
}