我已经为“创建”小部件创建了类。您调用静态函数,传递变量并拥有您的甜蜜小部件。
现在它起作用了,因为我一直在使用在小部件文件中创建的变量。但是现在我尝试使用一些“全局”变量并且它没有看到它。
“全局”是指我定义的全局变量(不是 phps),例如 $dic,它是字典类的对象。
这是为什么?我真的不想在每个小部件中创建这些变量。
我认为这是因为我正在创建临时文件。(我需要{{ title }}用实际标题替换,所以我得到小部件代码,替换标题,用替换的倾斜创建新的 tmp 文件并包含这个,然后删除)
全局变量:
$dic = new Dictionary(isset($_COOKIE["language"]) ? htmlspecialchars($_COOKIE["language"]) : _LANG); // THE GLOBAL VARIABLE
小部件代码:
<span>{{ title }}</span>
<form action="<?php echo Path::GetCurrentURL(); ?>" method="post">
<?php // for some reason it doesn't see any global variables so you have to create then once more in widgets which drives me nuts ugh?>
<input type="submit" name="logoutAdm" value="<?php $dic->Translate("Log out"); ?>">
</form>
包含功能:
{
$path = Path::Widgets("ShopPanelTitle.php");
if (file_exists($path)) {
$widget = file_get_contents($path);
$widget = str_replace("{{ title }}", $title, $widget);
$pathTmp = Tools::TMPName(".php",Path::TMP(""));
echo $pathTmp;
$file = fopen($pathTmp, "w+");
fwrite($file,$widget);
fclose($file);
// for some reason it doesn't see any global variables so you have to create then once more in widgets
include $pathTmp;
unlink($pathTmp);
}
}
我如何调用函数:
<?php Widgets::ShopPanelTitle($dic->Translate("Main",true)) ?>
没有更多相关的代码。如果您想查看所有使用的代码,问题会变得非常长,并且会因泄露公司机密而被起诉:/。
Path::Widgets - 返回小部件文件夹的路径
Tools::TMPName - 返回随机名称
我得到什么:
<span>Title</span>
<form action="currentPage.php" method="post">
</form>
我想得到什么:
<span>Title</span>
<form action="currentPage.php" method="post">
<input type="submit" name="logoutAdm" value="Log out">
</form>
湖上湖