diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 3819e0d..a98b36f 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -244,6 +244,7 @@ abstract class CommonController extends BaseController case 'login_form': case 'index': case 'view': + case 'download': $this->control = $this->getControlDatas(); $this->getHelper()->setViewDatas($this->getViewDatas()); $result = view($this->view_path . $this->getAction(), [ @@ -705,7 +706,7 @@ abstract class CommonController extends BaseController return array($full_path, $file_name); } // Download - final public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse + final public function download(string $output_type, mixed $uid = false): DownloadResponse|RedirectResponse|string { try { //각 Field 초기화 @@ -717,12 +718,13 @@ abstract class CommonController extends BaseController case 'pdf': // string buffer에서 읽어오는 경우 $this->entities = $this->index_process(); - $html = view('templates' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . __FUNCTION__, ['viewDatas' => $this->getViewDatas()]); + $html = $this->getResultSuccess(); //data loading $reader = new Html(); $loaded_data = $reader->loadFromString($html); list($full_path, $file_name) = $this->download_document($output_type, $loaded_data); $full_path .= DIRECTORY_SEPARATOR . $file_name; + return $this->response->download($full_path, null)->setFileName($file_name); break; default: if (!$uid) { @@ -735,9 +737,9 @@ abstract class CommonController extends BaseController $this->entity = $entity; list($file_name, $uploaded_filename) = $this->entity->getDownlaodFile(); $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $uploaded_filename; + return $this->response->download($full_path, null)->setFileName($file_name); break; } - return $this->response->download($full_path, null)->setFileName($file_name); } catch (\Exception $e) { return $this->getResultFail($e->getMessage()); } diff --git a/app/Views/templates/common/download.php b/app/Views/admin/download.php similarity index 61% rename from app/Views/templates/common/download.php rename to app/Views/admin/download.php index 3c52984..e0cd377 100644 --- a/app/Views/templates/common/download.php +++ b/app/Views/admin/download.php @@ -1,16 +1,16 @@
| = lang("{$viewDatas['class_path']}.label.{$field}") ?> |
|---|
| = $entity->$field ?> |