我想显示成功和错误通知 Mage::getSingleton('core/session')->addSuccess()->addError() 如果管理员位于特定配置部分。

原因:我做了一个扩展,其中有一个 单独的部分 在“系统/配置”中,我想反馈配置是否正确,但是 仅当管理员位于该部分时.

我尝试创建一个 default.notifications 块,该块有效,但通知是“全局通知”,而不是较小的通知框,它位于扩展程序设置字段的设置字段的顶部。还:仅当管理员位于此特定部分的配置页面时,我才想添加这些通知。

谢谢!

有帮助吗?

解决方案

您所指的留言区

enter image description here

填充自 Mage_Adminhtml_System_ConfigController::saveAction.

在设置消息之前,会发生一个事件("admin_system_config_changed_section_{$section})被解雇。

代码参考:

Mage::dispatchEvent("admin_system_config_changed_section_{$section}",
                array('website' => $website, 'store' => $store)
            );
            $session->addSuccess(Mage::helper('adminhtml')->__('The configuration has been saved.'));

您只需要弄清楚该部分中的内容($section = $this->getRequest()->getParam('section');)并且您很可能能够针对特定于您的部分保存的事件。

还有一个替代解决方案:使用管理部分中的提示字段。

将 HINT 组放入 system.xml 配置文件中。一个例子:

<hint>
   <frontend_model>dyncatprod/adminhtml_system_config_fieldset_hint</frontend_model>
     <sort_order>0</sort_order>
     <show_in_default>1</show_in_default>
     <show_in_website>1</show_in_website>
     <show_in_store>1</show_in_store>
</hint>

确保它具有最低的排序顺序。

您需要定义块类,下面是一个示例,根据 xml 示例显示路径。

enter image description here

它必须包含渲染方法

/**
     * Render fieldset html
     *
     * @param  Varien_Data_Form_Element_Abstract $element
     *
     * @return string
     */
    public function render(Varien_Data_Form_Element_Abstract $element)
    {
        return $this->toHtml();
    }

然后,您当然可以通过块输出您需要的任何内容,并运行您需要的任何逻辑 adminhtml_system_config_fieldset_hint

一个示例,输出有关已安装扩展的一些信息:

enter image description here

许可以下: CC-BY-SA归因
scroll top