shoppingmallv2 init...
This commit is contained in:
parent
800e5752dd
commit
3687e73a6c
@ -6,9 +6,11 @@ use App\Models\BoardModel;
|
|||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use App\Controllers\Trait\FileTrait;
|
||||||
|
|
||||||
class BoardController extends AdminController
|
class BoardController extends AdminController
|
||||||
{
|
{
|
||||||
|
use FileTrait;
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->_model = new BoardModel();
|
$this->_model = new BoardModel();
|
||||||
|
|||||||
@ -6,9 +6,11 @@ use App\Models\ProductModel;
|
|||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use App\Controllers\Trait\FileTrait;
|
||||||
|
|
||||||
class ProductController extends AdminController
|
class ProductController extends AdminController
|
||||||
{
|
{
|
||||||
|
use FileTrait;
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->_model = new ProductModel();
|
$this->_model = new ProductModel();
|
||||||
@ -45,7 +47,7 @@ class ProductController extends AdminController
|
|||||||
{
|
{
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'photo':
|
case 'photo':
|
||||||
$this->_viewDatas['fieldDatas'][$field] = $this->upload_photo_procedure($field);
|
$this->_viewDatas['fieldDatas'][$field] = $this->upload_image_procedure($field);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return parent::getFieldFormData($field, $entity);
|
return parent::getFieldFormData($field, $entity);
|
||||||
|
|||||||
@ -5,7 +5,6 @@ namespace App\Controllers;
|
|||||||
|
|
||||||
use CodeIgniter\Controller;
|
use CodeIgniter\Controller;
|
||||||
use CodeIgniter\HTTP\CLIRequest;
|
use CodeIgniter\HTTP\CLIRequest;
|
||||||
use CodeIgniter\HTTP\Files\UploadedFile;
|
|
||||||
use CodeIgniter\HTTP\IncomingRequest;
|
use CodeIgniter\HTTP\IncomingRequest;
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
@ -37,7 +36,7 @@ abstract class BaseController extends Controller
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $helpers = ['Common', 'Base'];
|
protected $helpers = ['Common'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Be sure to declare properties for any property fetch you initialized.
|
* Be sure to declare properties for any property fetch you initialized.
|
||||||
@ -94,58 +93,6 @@ abstract class BaseController extends Controller
|
|||||||
return $this->_viewDatas['fieldDatas'];
|
return $this->_viewDatas['fieldDatas'];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Upload FIle관련
|
|
||||||
private function upload_file_process(UploadedFile $upfile)
|
|
||||||
{
|
|
||||||
$fileName = null;
|
|
||||||
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
|
||||||
$originName = $upfile->getName();
|
|
||||||
$upfile->move(PATHS['UPLOAD'], $upfile->getRandomName());
|
|
||||||
//move시 중복된파일명이 있다면 파일명이 바뀌므로 여기서 한번더 파일명 확인 필요
|
|
||||||
$fileName = $originName . DEFAULTS['DELIMITER_FILE'] . $upfile->getName();
|
|
||||||
}
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
private function upload_image_process(UploadedFile $upfile, $sizeX = 100, $sizeY = 100)
|
|
||||||
{
|
|
||||||
//참고:https://www.positronx.io/codeigniter-resize-image-with-image-manipulation-tutorial/
|
|
||||||
$fileName = null;
|
|
||||||
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
|
||||||
$originName = $upfile->getName();
|
|
||||||
$fileName = $upfile->getRandomName();
|
|
||||||
$image = \Config\Services::image();
|
|
||||||
$image->withFile($upfile)
|
|
||||||
->resize($sizeX, $sizeY, true, 'height')
|
|
||||||
->save(PATHS['UPLOAD_PHOTO'] . $fileName);
|
|
||||||
$upfile->move(PATHS['UPLOAD_PHOTO'], "original_" . $fileName);
|
|
||||||
$fileName = $originName . DEFAULTS['DELIMITER_FILE'] . $fileName;
|
|
||||||
}
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
protected function upload_file_procedure(string $field)
|
|
||||||
{
|
|
||||||
return $this->upload_file_process($this->request->getFile($field));
|
|
||||||
}
|
|
||||||
protected function upload_photo_procedure(string $field, $sizeX = 100, $sizeY = 100)
|
|
||||||
{
|
|
||||||
return $this->upload_image_process($this->request->getFile($field), $sizeX, $sizeY);
|
|
||||||
}
|
|
||||||
protected function upload_multiple_file_process(string $field): array
|
|
||||||
{
|
|
||||||
//Multiple파일의경우 html에서는 필드명[]를 넣어야하며
|
|
||||||
//rule에서 "uploaded[필드명.0]|is_image[필드명]~~" 이런식으로 넣어야함
|
|
||||||
$fileNames = array();
|
|
||||||
if ($upfiles = $this->request->getFiles()) {
|
|
||||||
foreach ($upfiles[$field] as $upfile) {
|
|
||||||
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
|
||||||
$fileName = $this->upload_file_process($upfile);
|
|
||||||
array_push($this->_viewDatas['fieldDatas'][$field], $fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $fileNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
//초기화
|
//초기화
|
||||||
final public function init(string $action, $fields = null)
|
final public function init(string $action, $fields = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class BoardController extends FrontController
|
|||||||
}
|
}
|
||||||
public function getFields(string $action = ""): array
|
public function getFields(string $action = ""): array
|
||||||
{
|
{
|
||||||
$fields = ['title', "board_file", "passwd", "content"];
|
$fields = ['title', "passwd", "content"];
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case "index":
|
case "index":
|
||||||
case "excel":
|
case "excel":
|
||||||
@ -47,9 +47,6 @@ class BoardController extends FrontController
|
|||||||
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
|
$this->_viewDatas['fieldDatas'][$field] = $this->request->getVar($field);
|
||||||
$this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword');
|
$this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword');
|
||||||
break;
|
break;
|
||||||
case 'board_file':
|
|
||||||
$this->_viewDatas['fieldDatas'][$field] = $this->upload_file_procedure($field);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return parent::getFieldFormData($field, $entity);
|
return parent::getFieldFormData($field, $entity);
|
||||||
break;
|
break;
|
||||||
|
|||||||
85
app/Controllers/Trait/FileTrait.php
Normal file
85
app/Controllers/Trait/FileTrait.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\Trait;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\Files\UploadedFile;
|
||||||
|
|
||||||
|
trait FileTrait
|
||||||
|
{
|
||||||
|
//Upload FIle관련
|
||||||
|
private function upload_file_process(UploadedFile $upfile): string
|
||||||
|
{
|
||||||
|
$name = null;
|
||||||
|
$filename = null;
|
||||||
|
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||||
|
$name = $upfile->getName();
|
||||||
|
$filename = $upfile->getRandomName();
|
||||||
|
$upfile->move(PATHS['UPLOAD'], $filename);
|
||||||
|
//move시 중복된파일명이 있다면 파일명이 바뀌므로 여기서 한번더 파일명 확인 필요
|
||||||
|
$filename = $upfile->getName();
|
||||||
|
}
|
||||||
|
return $name . DEFAULTS['DELIMITER_FILE'] . $filename;
|
||||||
|
}
|
||||||
|
public function upload_file_procedure(string $field): string
|
||||||
|
{
|
||||||
|
return $this->upload_file_process($this->request->getFile($field));
|
||||||
|
}
|
||||||
|
public function upload_multiple_file_procedure(string $field): array
|
||||||
|
{
|
||||||
|
//Multiple파일의경우 html에서는 필드명[]를 넣어야하며
|
||||||
|
//rule에서 "uploaded[필드명.0]|is_image[필드명]~~" 이런식으로 넣어야함
|
||||||
|
$files = array();
|
||||||
|
if ($upfiles = $this->request->getFiles()) {
|
||||||
|
foreach ($upfiles[$field] as $upfile) {
|
||||||
|
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||||
|
array_push($files, $this->upload_file_process($upfile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function image_resize_process(UploadedFile $upfile, $filename, $x = 25, $y = 25)
|
||||||
|
{
|
||||||
|
$image = \Config\Services::image();
|
||||||
|
$image->withFile($upfile)
|
||||||
|
->resize($x, $y, true, 'height')
|
||||||
|
->save(PATHS['UPLOAD_PHOTO'] . $filename);
|
||||||
|
}
|
||||||
|
private function upload_image_process(UploadedFile $upfile): string
|
||||||
|
{
|
||||||
|
//참고:https://www.positronx.io/codeigniter-resize-image-with-image-manipulation-tutorial/
|
||||||
|
$name = null;
|
||||||
|
$filename = null;
|
||||||
|
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||||
|
$name = $upfile->getName();
|
||||||
|
$filename = $upfile->getRandomName();
|
||||||
|
$this->image_resize_process($upfile, "small_" . $filename);
|
||||||
|
$this->image_resize_process($upfile, "middle_" . $filename, 50, 50);
|
||||||
|
$this->image_resize_process($upfile, "large_" . $filename, 100, 100);
|
||||||
|
$upfile->move(PATHS['UPLOAD_PHOTO'], $filename);
|
||||||
|
//move시 중복된파일명이 있다면 파일명이 바뀌므로 여기서 한번더 파일명 확인 필요
|
||||||
|
$filename = $upfile->getName();
|
||||||
|
}
|
||||||
|
return $name . DEFAULTS['DELIMITER_FILE'] . $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upload_image_procedure(string $field): string
|
||||||
|
{
|
||||||
|
return $this->upload_image_process($this->request->getFile($field));
|
||||||
|
}
|
||||||
|
public function upload_multiple_image_procedure(string $field): array
|
||||||
|
{
|
||||||
|
//Multiple파일의경우 html에서는 필드명[]를 넣어야하며
|
||||||
|
//rule에서 "uploaded[필드명.0]|is_image[필드명]~~" 이런식으로 넣어야함
|
||||||
|
$names = array();
|
||||||
|
if ($upfiles = $this->request->getFiles()) {
|
||||||
|
foreach ($upfiles[$field] as $upfile) {
|
||||||
|
if ($upfile->isValid() && !$upfile->hasMoved()) {
|
||||||
|
array_push($files, $this->upload_image_process($upfile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -99,7 +99,7 @@ CREATE TABLE shoppingmall.tw_product (
|
|||||||
category_uid int(10) UNSIGNED NOT NULL COMMENT '상품분류',
|
category_uid int(10) UNSIGNED NOT NULL COMMENT '상품분류',
|
||||||
user_uid varchar(36) NULL COMMENT '생산자 정보',
|
user_uid varchar(36) NULL COMMENT '생산자 정보',
|
||||||
name varchar(255) NOT NULL COMMENT '상품명',
|
name varchar(255) NOT NULL COMMENT '상품명',
|
||||||
photo varchar(50) NULL COMMENT '이미지',
|
photo varchar(255) NULL COMMENT '이미지',
|
||||||
cost int(10) UNSIGNED NOT NULL COMMENT '원가',
|
cost int(10) UNSIGNED NOT NULL COMMENT '원가',
|
||||||
price int(10) UNSIGNED NOT NULL COMMENT '판매가',
|
price int(10) UNSIGNED NOT NULL COMMENT '판매가',
|
||||||
sale int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '할인가',
|
sale int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '할인가',
|
||||||
|
|||||||
@ -8,5 +8,4 @@ abstract class BaseEntity extends Entity
|
|||||||
{
|
{
|
||||||
abstract public function getPrimaryKey();
|
abstract public function getPrimaryKey();
|
||||||
abstract public function getTitle(): string;
|
abstract public function getTitle(): string;
|
||||||
abstract public function getStatus(): string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,9 +47,9 @@ class ProductEntity extends BaseEntity
|
|||||||
{
|
{
|
||||||
return $this->attributes['photo'];
|
return $this->attributes['photo'];
|
||||||
}
|
}
|
||||||
public function getPhotoBlock()
|
public function getPhotoFileName($size = 'small')
|
||||||
{
|
{
|
||||||
return explode(DEFAULTS['DELIMITER_FILE'], $this->attributes['photo'])[1];
|
return $size . '_' . explode(DEFAULTS['DELIMITER_FILE'], $this->attributes['photo'])[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent()
|
public function getContent()
|
||||||
|
|||||||
@ -130,7 +130,7 @@ function getFieldIndex_Row_OrderHelper_Admin($field, $entity, array $viewDatas):
|
|||||||
$field,
|
$field,
|
||||||
$field
|
$field
|
||||||
);
|
);
|
||||||
return getFieldForm_OrderHelper($field, $entity->field, $viewDatas, $attributes);
|
return getFieldForm_OrderHelper($field, $entity->$field, $viewDatas, $attributes);
|
||||||
}
|
}
|
||||||
return getFieldView_OrderHelper($field, $entity, $viewDatas);
|
return getFieldView_OrderHelper($field, $entity, $viewDatas);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -82,7 +82,8 @@ function getFieldView_ProductHelper($field, $entity, array $viewDatas)
|
|||||||
return $value == DEFAULTS['EMPTY'] ? DEFAULTS['EMPTY'] : anchor(current_url() . "/download/{$field}/{$entity->getPrimaryKey()}", ICONS['IMAGE_FILE'] . explode(DEFAULTS['DELIMITER_FILE'], $value)[0], ["target" => "_self"]);
|
return $value == DEFAULTS['EMPTY'] ? DEFAULTS['EMPTY'] : anchor(current_url() . "/download/{$field}/{$entity->getPrimaryKey()}", ICONS['IMAGE_FILE'] . explode(DEFAULTS['DELIMITER_FILE'], $value)[0], ["target" => "_self"]);
|
||||||
break;
|
break;
|
||||||
case 'photo':
|
case 'photo':
|
||||||
return "<img src=\"/upload_images/" . $entity->getPhotoBlock() . "\">";
|
// return $entity->getPhotoFileName();
|
||||||
|
return "<img src=\"/upload_images/" . $entity->getPhotoFileName() . "\">";
|
||||||
break;
|
break;
|
||||||
case 'cost':
|
case 'cost':
|
||||||
case 'price':
|
case 'price':
|
||||||
@ -138,7 +139,7 @@ function getFieldIndex_Row_ProductHelper_Admin($field, $entity, array $viewDatas
|
|||||||
$field,
|
$field,
|
||||||
$field
|
$field
|
||||||
);
|
);
|
||||||
return getFieldForm_ProductHelper($field, $entity->field, $viewDatas, $attributes);
|
return getFieldForm_ProductHelper($field, $entity->$field, $viewDatas, $attributes);
|
||||||
}
|
}
|
||||||
return getFieldView_ProductHelper($field, $entity, $viewDatas);
|
return getFieldView_ProductHelper($field, $entity, $viewDatas);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -133,7 +133,7 @@ function getFieldIndex_Row_UserSNSHelper_Admin($field, $entity, array $viewDatas
|
|||||||
$field,
|
$field,
|
||||||
$field
|
$field
|
||||||
);
|
);
|
||||||
return getFieldForm_UserSNSHelper($field, $entity->field, $viewDatas, $attributes);
|
return getFieldForm_UserSNSHelper($field, $entity->$field, $viewDatas, $attributes);
|
||||||
}
|
}
|
||||||
return getFieldView_UserSNSHelper($field, $entity, $viewDatas);
|
return getFieldView_UserSNSHelper($field, $entity, $viewDatas);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -139,7 +139,7 @@ function getFieldIndex_Row_UserHelper_Admin($field, $entity, array $viewDatas):
|
|||||||
$field,
|
$field,
|
||||||
$field
|
$field
|
||||||
);
|
);
|
||||||
return getFieldForm_UserHelper($field, $entity->field, $viewDatas, $attributes);
|
return getFieldForm_UserHelper($field, $entity->$field, $viewDatas, $attributes);
|
||||||
}
|
}
|
||||||
return getFieldView_UserHelper($field, $entity, $viewDatas);
|
return getFieldView_UserHelper($field, $entity, $viewDatas);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -94,9 +94,6 @@ abstract class BaseModel extends Model
|
|||||||
case "view_cnt":
|
case "view_cnt":
|
||||||
$rules[$field] = "if_exist|numeric";
|
$rules[$field] = "if_exist|numeric";
|
||||||
break;
|
break;
|
||||||
case "upload_file": //uploaded[{$field}] == requried와 같은의미
|
|
||||||
$rules[$field] = !$action ? "if_exist|string" : "is_image[{$field}]|mime_in[{$field},image/jpg,image/jpeg,image/gif,image/png,image/webp]|max_size[{$field},100]|max_dims[{$field},1024,768]";
|
|
||||||
break;
|
|
||||||
case "updated_at":
|
case "updated_at":
|
||||||
case "created_at":
|
case "created_at":
|
||||||
case "deleted_at":
|
case "deleted_at":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user