This commit is contained in:
2024-01-28 11:08:45 +07:00
parent 9052a3b7dd
commit 4fa4c3996f
7 changed files with 37 additions and 10 deletions

View File

@@ -48,13 +48,14 @@ class AppAdmin
str_replace("-", "_", $this->current_route_info["view"]).".php" str_replace("-", "_", $this->current_route_info["view"]).".php"
]) ; ]) ;
if(!file_exists($module_file)) { if(file_exists($module_file)) {
// print_r($this->current_route_info); // print_r($this->current_route_info);
die('Page '. $module_file .' not found!'); // die('Page '. $module_file .' not found!');
$data = include_once $module_file;
}else{
$data = ['file data '. $module_file .' not found!'];
} }
$data = include_once $module_file;
$global_data = [ $global_data = [
"module" => $this->current_route_info['module'], "module" => $this->current_route_info['module'],
"view" => $this->current_route_info['view'], "view" => $this->current_route_info['view'],
@@ -71,11 +72,16 @@ class AppAdmin
protected function renderModule() { protected function renderModule() {
$template_file_path = $this->tpl_path ."/". $this->current_route_info['module']."/".$this->current_route_info['view'].".html"; $template_file_path = $this->tpl_path ."/". $this->current_route_info['module'];
$template_file_name = $this->current_route_info['view'].".html";
$template_file_full_path = $template_file_path."/".$template_file_name;
//check exist //check exist
if(!@file_exists( $template_file_path)) { if(!@file_exists( $template_file_full_path)) {
die("Not found : ". $template_file_path); // attempt to auto create first
if(!$this->autoCreateTplFile( $template_file_path, $template_file_name )) {
die("Please manually create template file at: ". $template_file_full_path);
}
} }
$theme_file_path = $this->tpl_path ."/theme.html"; $theme_file_path = $this->tpl_path ."/theme.html";
@@ -84,7 +90,7 @@ class AppAdmin
} }
$theme_content = @file_get_contents( $theme_file_path ); $theme_content = @file_get_contents( $theme_file_path );
$module_content = @file_get_contents( $template_file_path ); $module_content = @file_get_contents( $template_file_full_path );
$page_content_to_parse = preg_replace([ $page_content_to_parse = preg_replace([
"/{{(\s+)?page_content(\s+)?}}/" "/{{(\s+)?page_content(\s+)?}}/"
@@ -99,6 +105,27 @@ class AppAdmin
); );
} }
protected function autoCreateTplFile($file_path, $file_name) : bool {
// create dir if not exist
if(!file_exists($file_path)) {
if(!mkdir($file_path, 0755, true)) {
return false;
}
if(!file_exists($file_path)) {
return false;
}
}
//create file
$file_full_path = $file_path . "/". $file_name;
@file_put_contents($file_full_path, $file_full_path);
return file_exists($file_full_path);
}
/* /*
* 2 ways to render a html template * 2 ways to render a html template
* 1. Use $html_to_parse, which requires no dependencies * 1. Use $html_to_parse, which requires no dependencies

View File

View File

View File

View File

View File

View File

@@ -31,7 +31,7 @@
<!-- Menu full --> <!-- Menu full -->
<div class="admin-menu-container box-menu sticky top-0 bottom-0 h-[100vh] hidden" id="js-menu-big"> <div class="admin-menu-container box-menu sticky top-0 bottom-0 h-[100vh] hidden" id="js-menu-big">
<a href="javascript:void(0)" class="icon-close" id="js-hide-menu"> <a href="javascript:void(0)" class="icon-close" title="Thu gọn menu" id="js-hide-menu">
<i class="fa-solid fa-outdent"></i> <i class="fa-solid fa-outdent"></i>
</a> </a>
@@ -116,7 +116,7 @@
<a href="/" class=""> <a href="/" class="">
<img src="../assets/images/logo_small.png" alt=""> <img src="../assets/images/logo_small.png" alt="">
</a> </a>
<a href="javascript:void(0)" class="icon-close" id="js-show-menu"> <a href="javascript:void(0)" title="Mở menu" class="icon-close" id="js-show-menu">
<i class="fa-solid fa-indent"></i> <i class="fa-solid fa-indent"></i>
</a> </a>
</div> </div>