trafficmonitor/app/Controllers/Admin/MylogController.php
2025-11-10 16:34:21 +09:00

60 lines
2.0 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\DTOs\MylogDTO;
use App\Entities\MylogEntity;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class MylogController extends AdminController
{
public const PATH = 'mylog';
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
if ($this->service === null) {
$this->service = service('mylogservice');
}
$this->addActionPaths($this::PATH);
}
//Action작업관련
protected function create_form_process(string $action): void
{
//Form Default값 설정
$formDatas = [];
$this->addViewDatas('formDatas', $formDatas);
}
protected function create_process(string $action): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new MylogDTO($this->request->getPost());
$entity = $this->service->create($dto);
return array($entity, "{$entity->getTitle()} 로그 생성이 완료되었습니다.");
}
protected function modify_form_process(string $action, $uid): void
{
if (!$uid) {
throw new \Exception("로그 번호가 정의 되지 않았습니다.");
}
$entity = $this->service->getEntity($uid);
if (!$entity instanceof MylogEntity) {
throw new \Exception("{$uid}에 해당하는 로그를 찾을수 없습니다.");
}
$this->addViewDatas('entity', $entity);
}
protected function modify_process(string $action, $uid): array
{
//요청 데이터를 DTO 객체로 변환
$dto = new MylogDTO($this->request->getPost());
$entity = $this->service->modify($uid, $dto);
return array($entity, "{$entity->getTitle()} 로그 수정이 완료되었습니다.");
}
protected function view_process($uid): MylogEntity
{
return parent::view_process($uid);
}
}