servermgrv2/app/Controllers/Front/BoardController.php
2023-07-27 17:21:55 +09:00

75 lines
2.7 KiB
PHP

<?php
namespace App\Controllers\Front;
use App\Models\BoardConfigModel;
use App\Models\BoardModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class BoardController extends FrontHierarchyController
{
private $_boardConfigModel = null;
private $_board_config_uids = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_className .= 'Board';
$this->_model = new BoardModel();
helper($this->_className);
$this->_viewPath .= strtolower($this->_className);
$this->_viewDatas['title'] = lang($this->_className . '.title');
$this->_viewDatas['className'] = $this->_className;
}
//BoardConfig모델
final protected function getBoardConfigModel(): BoardConfigModel
{
return is_null($this->_boardConfigModel) ? new BoardConfigModel() : $this->_boardConfigModel;
}
//Field별 Form Option용
protected function getFieldFormOption(string $field): array
{
switch ($field) {
case 'board_config_uid':
$options = $this->_board_config_uids = $this->_board_config_uids ?: $this->getBoardConfigModel()->getFieldFormOptions(['status' => 'use']);
break;
default:
return parent::getFieldFormOption($field);
break;
}
if (!is_array($options)) {
throw new \Exception(__FUNCTION__ . "에서 {$this->_className}의 Field:{$field}의 FormOptionData가 array가 아닙니다.\n" . var_export($options, true));
}
return $options;
}
//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)
{
// view_cnt에 추가하기위함
$this->_model->increaseViewCount($entity->getPrimaryKey());
return parent::view_process($entity);
}
}