47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\DTOs\UserDTO;
|
|
use App\Entities\UserEntity;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\Validation\Validation;
|
|
use Psr\Log\LoggerInterface;
|
|
use App\Services\UserService;
|
|
|
|
class UserController extends AdminController
|
|
{
|
|
/**
|
|
* @property UserService $service
|
|
* IDE에게 protected $service 속성이 LocalService 타입임을 알려줍니다.
|
|
*/
|
|
public const PATH = 'user';
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
if ($this->service === null) {
|
|
$this->service = service('userservice');
|
|
}
|
|
$this->addActionPaths($this::PATH);
|
|
}
|
|
protected function getFormRule(string $action, string $field, string $rule): array
|
|
{
|
|
switch ($field) {
|
|
case 'role':
|
|
$field = "{$field}.*";
|
|
break;
|
|
}
|
|
return parent::getFormRule($action, $field, $rule);
|
|
}
|
|
//Index,FieldForm관련.
|
|
protected function create_process(): UserEntity
|
|
{
|
|
//요청 데이터를 DTO 객체로 변환
|
|
$dto = new UserDTO($this->request->getPost());
|
|
return $this->service->create($dto);
|
|
}
|
|
}
|