首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento : System/Config在MultiSelect中添加自定义值

问Magento : System/Config在MultiSelect中添加自定义值
EN

Stack Overflow用户
提问于 2013-09-06 05:25:34
回答 1查看 12.5K关注 0票数 6

我创建了一个简单的模块。我创造了system.xml。有一个字段 multiselect ,我想在multiselect字段中添加自定义值。

是否可以在多选择字段中添加自定义值?

代码语言:javascript
复制
 <Data translate="label">
 <label>Select Socail Media</label>
 <comment>Select Social Media To fdisplay ion Front Side</comment>
 <front_end_type>multiselect</front_end_type>
 <source_model>adminhtml/system_config_source_country</source_model>
 <sort_order>3</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </Data>    

在多选择选项中,我想添加我的自定义选项,如: Data1、Data2、Data3等。

我怎么能这么做?有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-06 05:53:48

是的,您可以这样创建,将下面的代码添加到system.xml中

代码语言:javascript
复制
<fields>
    <view_style translate="label">
        <label>Display Settings</label>
        <frontend_type>multiselect</frontend_type>
        <source_model>yourmodule/system_config_source_view</source_model>
        <sort_order>40</sort_order>
        <show_in_default>1</show_in_default>
    </view_style>
</fields>

在此路径中为模块中的多选择选项创建一个文件

your_namespace/yourmodel/Model/System/Config/Source/View.php

在View.php中添加下面的代码

代码语言:javascript
复制
class YourNamespace_YourModule_Model_System_Config_Source_View 
{
    /**
     * Options getter
     *
     * @return array
     */
    public function toOptionArray()
    {
        return array(
            array('value' => 0, 'label' => Mage::helper('adminhtml')->__('Data1')),
            array('value' => 1, 'label' => Mage::helper('adminhtml')->__('Data2')),
            array('value' => 2, 'label' => Mage::helper('adminhtml')->__('Data3')),
        );
    }

    /**
     * Get options in "key-value" format
     *
     * @return array
     */
    public function toArray()
    {
        return array(
            0 => Mage::helper('adminhtml')->__('Data1'),
            1 => Mage::helper('adminhtml')->__('Data2'),
            3 => Mage::helper('adminhtml')->__('Data3'),
        );
    }
}

另外,有关更多细节,请使用此链接

希望这能对你有帮助。

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

https://stackoverflow.com/questions/18650487

复制
相关文章

相似问题

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