gpt4 book ai didi

magento-1.7 - Magento : System/Config Add Custom Value in MultiSelect

转载 作者:行者123 更新时间:2023-12-04 13:23:17 25 4
gpt4 key购买 nike

我创建了一个简单的模块。我已经创建了 system.xml。有一个字段多选 我想在多选字段中添加自定义值。

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

 <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 等。

我怎样才能做到这一点?是否可以?

最佳答案

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

<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 中添加以下代码
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'),
);
}
}

更多细节请使用 this link

希望这对你有帮助。

关于magento-1.7 - Magento : System/Config Add Custom Value in MultiSelect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18650487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com