如何将自定义模块页面的新链接添加到Prestashop 1.6.4的顶部水平菜单中

时间:2016-04-28 06:16:49

标签: prestashop prestashop-1.6

我创建了一个模块,它将挂钩到其中一个页面。但是如何在Prestashop 1.6的顶部水平菜单中显示我的自定义模块的链接。即当我导航到模块时 - >模块和查找顶级水平菜单。当我单击“配置”按钮访问模块配置页面时,如何在可用的“项目”列表中查看模块链接。即查看可用项目中的图像我想要我的自定义链接。我开发的自定义模块的链接。即,当我安装自定义模块时,链接必须显示在可用项目中,以便我可以添加自定义链接所选项目enter image description here

1 个答案:

答案 0 :(得分:2)

您有两种选择:

  • 在后台手动创建

    在blocktopmenu模块配置页面中,您可以在ADD A NEW LINK块下创建新的自定义链接。模块的链接为/module/your_module_name/your_controller_name。然后,您就可以将此链接添加到MENU TOP LINK下的菜单中。

  • 以编程方式创建

    在模块的安装方法中,您可以使用blocktopmenu方法创建此自定义链接。

    if (Module::isInstalled("blocktopmenu"))
    {
        // You will have to put the right path in here
        require_once('../blocktopmenu/menutoplinks.class.php');
    
        $languages = $this->context->controller->getLanguages();
        $shops = Shop::getContextListShopID();
    
        $links_label = array();
        $labels = array();
    
        foreach ($languages as $key => $val)
        {
            // You need to replace "my_module" and "my_controller" to get a link to your controller
            $links_label[$val['id_lang']] = Context::getContext()->link->getModuleLink("my_module", "my_controller");
            // Here set your link label for the menu
            $labels[$val['id_lang']] = "My Link Name";
        }
    
        foreach ($shops as $shop_id)
        {
            $added = MenuTopLinks::add($links_label, $labels, 0, (int) $shop_id);
            // You can check wether $added is true or false
    
        }
    }
    
  • 使用自动抑制以编程方式创建

    public function install()
    {
        if (! parent::install())
        {
            return false;
        }
    
        if (Module::isInstalled("blocktopmenu"))
        {
            // You will have to put the right path in here
            require_once('../blocktopmenu/menutoplinks.class.php');
    
            $languages = $this->context->controller->getLanguages();
            $shops = Shop::getContextListShopID();
    
            foreach ($shops as $shop_id)
            {
    
                $links_label = array();
                $labels = array();
    
                foreach ($languages as $key => $val)
                {
                    // You need to replace "my_module" and "my_controller" to get a link to your controller
                    $links_label[$val['id_lang']] = Context::getContext()->link->getModuleLink("my_module", "my_controller", array(), null, $val['id_lang'], $shop_id);
                    // Here set your link label for the menu
                    $labels[$val['id_lang']] = "My Link Name";
                }
    
                $added = MenuTopLinks::add($links_label, $labels, 0, (int) $shop_id);
    
                if ($added) {
                    $link_id = Db::getInstance()->getValue("
                        SELECT DISTINCT id_linksmenutop
                        FROM `"._DB_PREFIX_."linksmenutop_lang`
                        WHERE link LIKE '" . $link . "'
                        AND id_shop LIKE '" . $shop_id . "'
                    ");
    
                    Configuration::set("MY_MODULE_LINKS_TOP_" . $shop_id, $link_id);
                }
            }
        }
    }
    
    public function uninstall()
    {
        if (! parent::uninstall())
        {
            return false;
        }
    
        if (Module::isInstalled("blocktopmenu"))
        {
            // You will have to put the right path in here
            require_once('../blocktopmenu/menutoplinks.class.php');
    
            $shops = Shop::getContextListShopID();
    
            foreach ($shops as $shop_id)
            {
                $link_id = Configuration::get("MY_MODULE_LINKS_TOP_" . $shop_id);
    
                if ($link_id !== false)
                {
                    MenuTopLinks::remove($link_id, $shop_id);
                }
            }
        }
    }
    

    代码未经测试但必须使用Prestashop 1.6。

相关问题