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"
]) ;
if(!file_exists($module_file)) {
if(file_exists($module_file)) {
// 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 = [
"module" => $this->current_route_info['module'],
"view" => $this->current_route_info['view'],
@@ -71,11 +72,16 @@ class AppAdmin
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
if(!@file_exists( $template_file_path)) {
die("Not found : ". $template_file_path);
if(!@file_exists( $template_file_full_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";
@@ -84,7 +90,7 @@ class AppAdmin
}
$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([
"/{{(\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
* 1. Use $html_to_parse, which requires no dependencies