我已经为“创建”小部件创建了类。你调用静态函数,传递变量,并有你的甜蜜小部件。
现在它有效,因为我一直在使用在小部件文件中创建的变量。但现在我试图使用一些“全局”变量,但它没有看到它。
通过“全局”,我的意思是我定义的全局变量(不是phps),就像$dic它是字典类的对象。
为什么?我真的不想在每个小部件中创建这些变量。
我想这是因为我正在创建临时文件。(我需要用实际的标题替换,所以我得到小部件代码,替换标题,用替换的tiltle创建新的tmp文件并包含这个,然后删除){{ title }}
全局变量:
$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)) ?>
没有更多相关的代码。如果你想看到所有使用的代码,这个问题会变得非常长,并且会因为泄露公司机密而被起诉:/。
路径::小部件 - 返回小部件文件夹的路径
工具::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>
慕田峪7331174