servermgrv2/app/Controllers/Front/BoardController.php
최준흠git config git config --helpgit config --global user.name 최준흠 d2a11bc1ed servermgrv2 init...
2023-08-03 22:32:00 +09:00

70 lines
2.3 KiB
PHP

<?php
namespace App\Controllers\Front;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class BoardController extends FrontController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new BoardModel($this->getFields());
parent::initController($request, $response, $logger);
$this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title');
$this->_viewPath .= strtolower($this->_model->getClassName());
helper($this->_model->getClassName());
}
public function getFields(string $action = ""): array
{
$fields = ["category_uid", 'title', "board_file", "passwd", "content"];
switch ($action) {
case "index":
case "excel":
return ["category_uid", "user_uid", 'title', "board_file", "view_cnt", "created_at"];
break;
case "view":
return ["category_uid", "user_uid", 'title', "board_file", "view_cnt", "created_at", "content"];
break;
default:
return $fields;
break;
}
}
public function getFieldFilters(): array
{
return ["category_uid", "user_uid"];
}
public function getFieldBatchFilters(): array
{
return parent::getFieldBatchFilters();
}
//Field별 Form Datas 처리용
protected function getFieldFormData(string $field, $entity = null): array
{
switch ($field) {
case 'passwd':
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
$this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword');
break;
case 'board_file':
$this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity);
break;
default:
return parent::getFieldFormData($field, $entity);
break;
}
return $this->_viewDatas['fieldDatas'];
}
//View관련
protected function view_process($entity)
{
$entity = parent::view_process($entity);
return $this->_model->addViewCount($entity);
}
}