首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从我的对象模型中获取值并在Prestashop的标题上显示我的横幅

如何从我的对象模型中获取值并在Prestashop的标题上显示我的横幅
EN

Stack Overflow用户
提问于 2021-03-27 06:08:00
回答 1查看 142关注 0票数 1

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

我的模块表单:

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

我尝试使用smarty和orm来检索所有信息,但我不知道如何在标题中显示。

有什么问题吗?我希望我能理解我的问题:)

谢谢

下面是我的一些文件的代码:

代码语言:javascript
复制
//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> 
EN

回答 1

Stack Overflow用户

发布于 2021-03-27 15:34:02

使用:

代码语言:javascript
复制
return Db::getInstance()->getRow($sql);

只检索结果的第一行,如果您希望返回多个横幅,则希望使用Db::getInstance()->executeS($sql);来获取所有结果。

还要检查您的DB表结构和相关变量的var_dump(),这将有助于了解是否存在更多问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66824875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档