shoppingmallv2/app/Controllers/Front/FrontController.php
최준흠git config git config --helpgit config --global user.name 최준흠 41f1c932c0 shoppingmall init...
2023-08-05 13:10:06 +09:00

56 lines
2.0 KiB
PHP

<?php
namespace App\Controllers\Front;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Models\CategoryModel;
abstract class FrontController extends BaseController
{
protected $_category = null;
private $_categoryModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->_viewPath .= 'front/';
$this->_viewDatas['layout'] = LAYOUTS['front'];
}
final protected function getCategoryModel(): CategoryModel
{
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
}
//권한체크
final protected function isRole($action, $entity = null)
{
$this->_category = !is_null($entity) ? $entity->getCategory_Uid() : ($this->request->getVar('category') ?: throw new \Exception("범주를 지정하지 않으셨습니다."));
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]);
switch ($action) {
case 'insert':
$category_field = CATEGORY_ROLE_FIELDS['WRITE'];
break;
case 'reply':
$category_field = CATEGORY_ROLE_FIELDS['REPLY'];
break;
case 'view':
$category_field = CATEGORY_ROLE_FIELDS['READ'];
break;
default:
$category_field = CATEGORY_ROLE_FIELDS['ACCESS'];
break;
}
//사용자가 Category에서 해당 게시판의 해당권한이 있는지 확인
if (!isRole_CommonHelper(
$this->_viewDatas['currentRoles'],
$this->_viewDatas['category'],
$category_field,
)) {
throw new \Exception("고객님은 " . lang('Category' . $category_field) . "이 없습니다.");
}
}
}