【问题标题】:Magento module system.xml checkbox won't saveMagento 模块 system.xml 复选框不会保存
【发布时间】:2011-08-26 15:05:36
【问题描述】:

在 Magento v1.5.0.1 中,有人知道在 system.xml 中使用 <frontend_type>checkbox</frontend_type> 配置指令的问题吗?即使在只有一个配置变量且没有块/模型的最简单的哑模块中,如果我选中该框并点击“保存”,它也会重新加载页面并取消选中该复选框,即使它表示配置已成功保存。我搜索了代码,它只在几个地方使用。大多数时候,人们使用<frontend_type>select</frontend_type><source_model>adminhtml/system_config_source_yesno</source_model>。这行得通,但为什么复选框也不起作用?还是我误解了 Magento 复选框应该是如何工作的?

如果有帮助,这是我的文件。在这种情况下,我还添加了一个文本字段变量。如果我输入文本并点击保存,那会保存,但复选框不会:

config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Brian_Stupid>
            <version>0.1.0</version>
        </Brian_Stupid>
    </modules>
    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <stupid translate="title">
                                            <title>Stupid Crap</title>
                                        </stupid>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

system.xml:

<?xml version="1.0"?>
<config>
    <sections>
        <stupid translate="label">
            <label>Stupid Test</label>
            <tab>catalog</tab>
            <frontend_type>text</frontend_type>
            <sort_order>998</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <debug translate="label">
                    <label>Debugging</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>5</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <debugmode translate="label">
                            <label>Debug Mode Enable</label>
                            <comment>If enabled, does not alter database. Prints debug messages and dies</comment>
                            <frontend_type>checkbox</frontend_type>
                            <sort_order>5</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </debugmode>
                        <texttest translate="label">
                            <label>Text Test</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </texttest>
                    </fields>
                </debug>
            </groups>
        </stupid>
    </sections>
</config>

【问题讨论】:

    标签: magento magento-1.5


    【解决方案1】:

    当我面临类似情况时,我将我的解决方案发布给您

    基本上问题是magento只将输入参数'value'保存在db中,而在输入复选框中重要的值是'Checked'。

    我试着放一些js,当复选框改变时根据这个设置输入值,当页面加载相反时......这不起作用。

    替代解决方案:使用下拉菜单

     <debugmode translate="label">
                            <label>Debug Mode Enable</label>
                            <comment>If enabled, does not alter database. Prints debug messages and dies</comment>
                            <frontend_type>select</frontend_type>                                                                     
                            <source_model>adminhtml/system_config_source_yesno</source_model>     
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </debugmode>
    

    【讨论】:

      【解决方案2】:

      我花了一些时间来寻找解决方案,但没有一个,除了一个。

      看看 Mage-Folder 中的 PayPal 模块。那是唯一使用 Checkboxed 的模块,但它们的设置方式相当困难。

      我想这就是为什么每个人都使用带有 yesno 或可启用源的 select 的原因。

      【讨论】:

      • 我在 PayPal 模块中也注意到了这一点,但无法弄清楚。有时间我会再看看它,看看我是否能理解它。目前,是/否工作正常,但我希望有人阅读此线程,了解更多有关复选框的信息。有人吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 2014-02-16
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多