我开发了一个自定义的多横幅模块,显示在我的prestashop页面的页眉上。当我在表单上保存我的更改时,我想在页眉上显示它。
我的模块表单:

我的表格要查看插入的所有横幅:

我尝试使用smarty和orm来检索所有信息,但我不知道如何在标题中显示。
有什么问题吗?我希望我能理解我的问题:)
谢谢
下面是我的一些文件的代码:
//in main file:
public function hookDisplayHeaderBanner($params) {
$banner = Banner::getBannerToDisplay();
// If there is a banner to display
if ($banner) {
$this->context->smarty->assign([
'banner' => $banner
]);
return $this->display(__FILE__, 'views/templates/hook/display-custom-banner.tpl');
}
// Nothing to display
return false;
}
//In classes/Banner.php
class Banner extends ObjectModel
{
public $id;
public $color;
public $background_color;
public $content;
public static $definition = [
'table' => 'custom_banner',
'primary' => 'id_custom_banner',
'multilang' => false,
'fields' => [
'color' => [
'type' => self::TYPE_STRING,
],
'background_color' => [
'type' => self::TYPE_STRING,
],
'content' => [
'type' => self::TYPE_STRING
]
]
];
/*
*
* Return the banner to display
*
* Here we put the logic to select the right banner
*/
public static function getBannerToDisplay()
{
$sql = 'SELECT *
FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
WHERE active = 1';
return Db::getInstance()->getRow($sql);
}
}
//In display-custom-banner.tpl
<div id="banner" style="background-color:{$banner.background_color}!important;">
<p style="color:{$banner.color}!important;">
{$banner.content}
</p>
</div> 发布于 2021-03-27 15:34:02
使用:
return Db::getInstance()->getRow($sql);只检索结果的第一行,如果您希望返回多个横幅,则希望使用Db::getInstance()->executeS($sql);来获取所有结果。
还要检查您的DB表结构和相关变量的var_dump(),这将有助于了解是否存在更多问题。
https://stackoverflow.com/questions/66824875
复制相似问题