【问题标题】:when adding two items in config.xml to show the navigation. Why does It display only one?在 config.xml 中添加两个项目以显示导航时。为什么它只显示一个?
【发布时间】:2017-02-21 09:48:11
【问题描述】:

我正在处理magento 的项目,我试图在主导航中列出一个菜单项。其中每个模型有一个observer。我要做的是使用现有的观察者添加另一个菜单项。为此我创建了一个函数:

class Color_Observer{
    // Existing function for "colors" menu item.
    public function ListMenuItems(){
        //code here 
    }

    // New function for "composite colors" menu item
    public function MyListMenuItems(){ 
        // 
    }
}

我在config.xml中添加了以下代码

<frontend>
      <events>
         <page_block_html_topmenu_gethtml_before>
            <observers>
               <my_color>
                  <class>my_color/observer</class>
                  <method>ListMenuItems</method>
               </my_color>
               <my_color_val>
                  <class>my_color/observer</class>
                  <method>MyListMenuItems</method>
               </my_color_val>
            </observers>
         </page_block_html_topmenu_gethtml_before>
      </events>
</frontend>

此代码成功为composite colors 创建菜单,但它替换了现有的color 菜单。

谁能帮我看看这是怎么回事?我是magento 的新手。

【问题讨论】:

标签: xml magento


【解决方案1】:

添加观察者类型&lt;type&gt;singleton&lt;/type&gt;

<frontend>
      <events>
         <page_block_html_topmenu_gethtml_before>
            <observers>
               <my_color>
                  <class>my_color/observer</class>
                  <type>singleton</type>
                  <method>ListMenuItems</method>
               </my_color>
               <my_color_val>
                  <class>my_color/observer</class>
                  <type>singleton</type>
                  <method>MyListMenuItems</method>
               </my_color_val>
            </observers>
         </page_block_html_topmenu_gethtml_before>
      </events>
</frontend>

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    相关资源
    最近更新 更多