diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6134647..988bbc0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -39,6 +39,10 @@ $routes->get('/login', 'AuthController::login'); $routes->post('/signup', 'AuthController::signup/local'); $routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); $routes->get('/logout', 'AuthController::logout'); +$routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) { + $routes->post('addCart', 'CartController::addCart'); + $routes->get('cancelCart', 'CartController::cancelCart'); +});; $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 @@ -152,10 +156,6 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou $routes->get('', 'OrderController::index'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); });; - $routes->group('cart', static function ($routes) { - $routes->post('addCart', 'CartController::addCart'); - $routes->post('cancelCart', 'CartController::cancelCart'); - });; }); /* * -------------------------------------------------------------------- diff --git a/app/Config/Routes_Shoppinmall.php b/app/Config/Routes_Shoppinmall.php index 6134647..2754026 100644 --- a/app/Config/Routes_Shoppinmall.php +++ b/app/Config/Routes_Shoppinmall.php @@ -39,6 +39,10 @@ $routes->get('/login', 'AuthController::login'); $routes->post('/signup', 'AuthController::signup/local'); $routes->get('/signup/(:alpha)', 'AuthController::signup/$1'); $routes->get('/logout', 'AuthController::logout'); +$routes->group('cart', ['namespace' => 'App\Controllers'], static function ($routes) { + $routes->post('addCart', 'CartController::addCart'); + $routes->get('cancelCart', 'CartController::cancelCart'); +});; $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { }); // authGuard는 App\Config\Filters.php의 $aliases에 선언한 이름이어야 함 @@ -151,11 +155,7 @@ $routes->group('front', ['namespace' => 'App\Controllers\Front'], function ($rou $routes->group('order', static function ($routes) { $routes->get('', 'OrderController::index'); $routes->get('view/(:uuid)', 'OrderController::view/$1'); - });; - $routes->group('cart', static function ($routes) { - $routes->post('addCart', 'CartController::addCart'); - $routes->post('cancelCart', 'CartController::cancelCart'); - });; + }); }); /* * -------------------------------------------------------------------- diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index ed71d02..adf8c30 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -2,17 +2,17 @@ namespace App\Controllers\Admin; +use App\Models\BoardConfigModel; use App\Models\BoardModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -use App\Models\BoardConfigModel; class BoardController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_model = new BoardModel($this->getFields()); + $this->_model = new BoardModel(); parent::initController($request, $response, $logger); $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); $this->_viewPath .= strtolower($this->_model->getClassName()); diff --git a/app/Controllers/Admin/OrderController.php b/app/Controllers/Admin/OrderController.php index 0f25434..c2f25c6 100644 --- a/app/Controllers/Admin/OrderController.php +++ b/app/Controllers/Admin/OrderController.php @@ -11,7 +11,7 @@ class OrderController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_model = new OrderModel($this->getFields()); + $this->_model = new OrderModel(); parent::initController($request, $response, $logger); $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); $this->_viewPath .= strtolower($this->_model->getClassName()); diff --git a/app/Controllers/Admin/ProductController.php b/app/Controllers/Admin/ProductController.php index 986935d..c564a2b 100644 --- a/app/Controllers/Admin/ProductController.php +++ b/app/Controllers/Admin/ProductController.php @@ -2,17 +2,17 @@ namespace App\Controllers\Admin; +use App\Models\CategoryModel; use App\Models\ProductModel; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; -use App\Models\CategoryModel; class ProductController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_model = new ProductModel($this->getFields()); + $this->_model = new ProductModel(); parent::initController($request, $response, $logger); $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); $this->_viewPath .= strtolower($this->_model->getClassName()); diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index c14ba9d..8b5a6fe 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -11,7 +11,7 @@ class UserController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_model = new UserModel($this->getFields()); + $this->_model = new UserModel(); parent::initController($request, $response, $logger); $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); $this->_viewPath .= strtolower($this->_model->getClassName()); diff --git a/app/Controllers/Admin/UserSNSController.php b/app/Controllers/Admin/UserSNSController.php index d7b0e07..72fa184 100644 --- a/app/Controllers/Admin/UserSNSController.php +++ b/app/Controllers/Admin/UserSNSController.php @@ -11,7 +11,7 @@ class UserSNSController extends AdminController { public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - $this->_model = new UserSNSModel($this->getFields()); + $this->_model = new UserSNSModel(); parent::initController($request, $response, $logger); $this->_viewDatas['title'] = lang($this->_model->getClassName() . '.title'); $this->_viewPath .= strtolower($this->_model->getClassName()); diff --git a/app/Controllers/CartController.php b/app/Controllers/CartController.php index 7e5c635..47030b2 100644 --- a/app/Controllers/CartController.php +++ b/app/Controllers/CartController.php @@ -51,22 +51,15 @@ class CartController extends Controller } private function getOrderModel() { - return $this->_orderModel = $this->_orderModel ?: new OrderModel(); + return $this->_orderModel = $this->_orderModel ?: new OrderModel(["product_uid", "quantity", "price", "status"]); } private function getProductModel() { return $this->_productModel = $this->_productModel ?: new ProductModel(); } - final public function init() - { - $this->_viewDatas['fields'] = ["product_uid", "quantity", "price", "status"]; - $this->_viewDatas['fieldRules'] = $this->getOrderModel()->getFieldRules($this->_viewDatas['fields']); - return $this->_viewDatas; - } - //주문 - protected function addCart_validate() + private function addCart_validate() { //fieldData Rule 검사 if (!$this->validate($this->_viewDatas['fieldRules'])) { @@ -75,7 +68,7 @@ class CartController extends Controller //fieldData 적용 $this->_viewDatas['fieldDatas'] = array(); foreach ($this->_viewDatas['fields'] as $field) { - $this->_viewDatas['fieldDatas'] = $this->request->getVar($field); + $this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field); } } @@ -83,7 +76,8 @@ class CartController extends Controller { $msg = ""; try { - $this->_viewDatas = $this->init(__FUNCTION__); + $this->_viewDatas['fields'] = ["product_uid", "quantity", "price", "status"]; + $this->_viewDatas['fieldRules'] = $this->getOrderModel()->getFieldRules($this->_viewDatas['fields']); //Transaction 시작 $this->getOrderModel()->transStart(); //장바구니정보 검증 @@ -103,6 +97,8 @@ class CartController extends Controller $this->_viewDatas['fieldDatas'][$this->getOrderModel()->getTitleField()] = $product->getTitle(); //주문추가 $entity = $this->getOrderModel()->addCart($this->_viewDatas['fieldDatas']); + echo var_export($entity, true); + exit; //상품재고감소 $this->getProductModel()->addCart($product, $this->_viewDatas['fieldDatas']['quantity']); //주문정보 세션에 넣기 diff --git a/app/Entities/OrderEntity.php b/app/Entities/OrderEntity.php index 57a855b..7191a99 100644 --- a/app/Entities/OrderEntity.php +++ b/app/Entities/OrderEntity.php @@ -40,8 +40,4 @@ class OrderEntity extends BaseEntity { return $this->attributes['quantity']; } - public function geSession_Id() - { - return $this->attributes['sess_id']; - } } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 49f7463..26b48aa 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -47,7 +47,7 @@ abstract class BaseModel extends Model { $this->_className = $className; parent::__construct(); - $this->allowedFields = ["updated_at", "created_at"]; + $this->allowedFields = ["uid", "updated_at", "created_at"]; if (!$this->useAutoIncrement) { array_push($this->allowedFields, $this->primaryKey); } diff --git a/app/Models/BoardConfigModel.php b/app/Models/BoardConfigModel.php index 88f0cc8..8d37996 100644 --- a/app/Models/BoardConfigModel.php +++ b/app/Models/BoardConfigModel.php @@ -9,10 +9,14 @@ class BoardConfigModel extends BaseModel protected $table = "tw_board_config"; protected $useAutoIncrement = false; protected $returnType = BoardConfigEntity::class; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('BoardConfig'); - $this->allowedFields = [...$this->allowedFields, ...$fields]; + $this->allowedFields = [ + ...$this->allowedFields, + 'name', "isaccess", "isread", "iswrite", "isreply", "isupload", "isdownload", + "head", "tail", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string diff --git a/app/Models/BoardModel.php b/app/Models/BoardModel.php index ad685a2..de21620 100644 --- a/app/Models/BoardModel.php +++ b/app/Models/BoardModel.php @@ -9,10 +9,15 @@ class BoardModel extends BaseHierarchyModel private $_boardconfig_options = null; protected $table = "tw_board"; protected $returnType = BoardEntity::class; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('Board'); - $this->allowedFields = [...$this->allowedFields, "user_uid", ...$fields]; + $this->allowedFields = [ + ...$this->allowedFields, + "board_config_uid", + "user_uid", 'title', "content", + "passwd", "board_file", "view_cnt", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string diff --git a/app/Models/CategoryModel.php b/app/Models/CategoryModel.php index 95db96f..f80e2b0 100644 --- a/app/Models/CategoryModel.php +++ b/app/Models/CategoryModel.php @@ -9,10 +9,10 @@ class CategoryModel extends BaseHierarchyModel //BaseHierarchyModel를 확장하면 grpno가 숫자이고, primarykey를 대분류 생성시 copy하여 grpno에 넣고 sorting하므로 protected $table = "tw_category"; protected $returnType = CategoryEntity::class; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('Category'); - $this->allowedFields = [...$this->allowedFields, ...$fields]; + $this->allowedFields = [...$this->allowedFields, 'name', "head", "tail", "status"]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string diff --git a/app/Models/OrderModel.php b/app/Models/OrderModel.php index 79d228a..b26e89e 100644 --- a/app/Models/OrderModel.php +++ b/app/Models/OrderModel.php @@ -11,10 +11,10 @@ class OrderModel extends BaseModel protected $useAutoIncrement = false; protected $returnType = OrderEntity::class; protected $useSoftDeletes = true; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('Order'); - $this->allowedFields = ["uid", "user_uid", "name", ...$this->allowedFields, ...$fields]; + $this->allowedFields = [...$this->allowedFields, 'product_uid', "user_uid", "name", "quantity", "price", "status"]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } final public function getTitleField(): string diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php index bf0f1a5..c28e3f8 100644 --- a/app/Models/ProductModel.php +++ b/app/Models/ProductModel.php @@ -11,10 +11,15 @@ class ProductModel extends BaseModel protected $useAutoIncrement = false; protected $returnType = ProductEntity::class; protected $useSoftDeletes = true; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('Product'); - $this->allowedFields = ["uid", "user_uid", ...$this->allowedFields, ...$fields]; + $this->allowedFields = [ + ...$this->allowedFields, + "category_uid", "user_uid", + 'name', "photo", "cost", "price", "sale", + "stock", "view_cnt", "content", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index ec065f3..e3de42d 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -10,10 +10,13 @@ class UserModel extends BaseModel protected $useAutoIncrement = false; protected $returnType = UserEntity::class; protected $useSoftDeletes = true; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('User'); - $this->allowedFields = ["uid", ...$this->allowedFields, ...$fields]; + $this->allowedFields = [ + ...$this->allowedFields, + "id", "passwd", 'name', "email", "role", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string diff --git a/app/Models/UserSNSModel.php b/app/Models/UserSNSModel.php index 05f96f5..9017e3a 100644 --- a/app/Models/UserSNSModel.php +++ b/app/Models/UserSNSModel.php @@ -8,10 +8,13 @@ class UserSNSModel extends BaseModel { protected $table = "tw_user_sns"; protected $returnType = UserSNSEntity::class; - public function __construct(array $fields = array()) + public function __construct() { parent::__construct('UserSNS'); - $this->allowedFields = [...$this->allowedFields, "user_uid", ...$fields]; + $this->allowedFields = [ + ...$this->allowedFields, + "site", "id", 'name', "email", "detail", "status" + ]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string diff --git a/app/Views/front/order/index.php b/app/Views/front/order/index.php index 5a0b3db..d54523e 100644 --- a/app/Views/front/order/index.php +++ b/app/Views/front/order/index.php @@ -26,7 +26,7 @@ getStatus() == DEFAULTS['STATUS']) : ?> - getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> + getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> diff --git a/app/Views/front/product/addCart.php b/app/Views/front/product/addCart.php index 7954846..0ad13d5 100644 --- a/app/Views/front/product/addCart.php +++ b/app/Views/front/product/addCart.php @@ -1,4 +1,4 @@ - 'post']) ?> + 'post']) ?> getPrimaryKey()) ?>