问题描述
我创建了一个简单的模块.我已经创建了system.xml.我想在 Multiselect 字段中添加自定义值.
i have created one simple Module. i have created system.xml. there is one field Multiselect i want to add custom Value in multiselect field.
是否可以在多选字段中添加自定义值?
is it possible to add custom Value in multiselect field ?
<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等.
in Multiselect Options i want to add my Custom Option like: Data1, Data2 , Data3 etc..
我该怎么做?有可能吗?
how can i do that? is it possible?
推荐答案
是的,您可以像这样创建,将以下代码添加到system.xml
yes you can create like this way add below code to 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>
在此路径中的模块中为multiselect选项创建一个文件
create one file for multiselect option in your module in this path
您的名称空间/您的模型/模型/系统/配置/源/View.php
your_namespace/yourmodel/Model/System/Config/Source/View.php
在View.php中添加以下代码
Add below code in your 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'),
);
}
}
有关更多详细信息,请使用此链接
Also for more detail use this link
希望这一定会对您有所帮助.
hope this will sure help you.
这篇关于Magento:系统/配置在MultiSelect中添加自定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!