我想创建自己的模板来构建我的下一个Web项目。
但我的问题是我正在尝试使用自己的功能创建自己的模板系统,同时也要了解有关编码的更多信息。
我试图改进我的代码,以便在编码时保持干净/顺畅。
但现在我遇到了这个问题
一功能-file.php
<?php
$Website_info = array("SiteTitle"=>"CLiCK", "BaseUrl"=>"http://localhost/CLick/");
//css styles her
$website_styles = array(
array("src"=>"libs/css/bootstrap.min.css", "type"=>"text/css"),
array("src"=>"libs/themes/click.css", "type"=>"text/css")
);
//javascripts her
$website_scripts = array(
array("src"=>"libs/js/bootstrap.min.js", "type"=>"text/javascript")
);
$website_navigation_top_links = array(
array("link"=>"index.php","name"=>"Home")
);
function Click_styles()
{
global $website_styles;
$styleOutput = "";
foreach ($website_styles as $key => $CssStyle):
$styleOutput .= "<link href='".$CssStyle["src"]."' rel='stylesheet' type='".$CssStyle["type"]."'>\n";
endforeach;
return $styleOutput;
}
//my function to create html codes within head tags
function Click_header()
{
//Getting website info into function
global $Website_info;
global $website_styles;
$ImpotedStyles = Click_styles();
//creating the html (can maybe be created more clean later)
$Header_output = "<title>".$Website_info["SiteTitle"]."</title>\n";
$Header_output .= "<base href='".$Website_info["BaseUrl"]."' />\n";
$Header_output = $Header_output.$ImpotedStyles;
// return the complied output (as HTML)
return $Header_output;
}
?>
到目前为止一切顺利,因为如果我写
,这是有效的<?php echo Click_header();?>
但我希望通过将函数作为参数传递给
来使用这样的函数<?php
//the function that doesnt work
function printHTML($ThisShouldBeAFunctionNotAVar, $Description="none") {
echo $ThisShouldBeAFunctionNotAVar
}
?>
<?php
//how I want to use the function
printHTML(Click_header(), "The website header");
//and maybe if I had a footer I could display the return of that function too
printHTML(Click_foter(), "a smart footer function");
?>
我希望你可以帮助我,或者更好地了解一些更聪明的东西
答案 0 :(得分:0)
我在自己的
上安装了这个解决方案<?php
function printHTML($CustomFunction,$Description="")
{
$function = ($CustomFunction;
echo $function();
}
?>