我在phtml页面中写了这两行:
$array = Mage::getStoreConfig('extcontacts/extendedcontactsGroup');
var_dump($array);
这就是结果:
array (size=8)
'excontactus_select' => string '1' (length=1)
'defaultrecipient_text' => string 'soufiane.marar1@gmail.com' (length=25)
'departements_textarea' => string 'Sales Department,sales@example.com
Support Department,support@example.com' (length=74)
'staticblock_select' => string '1' (length=1)
'contactfrm_select' => string '0' (length=1)
'emailsender_select' => string 'general' (length=7)
'sendcopytosender_select' => string '0' (length=1)
'emailtemplate_select' => string 'extcontacts_extendedcontacts_group_emailtemplate_select' (length=55)
对于select,它返回1或0,我不希望返回1或0我想要字符串。
staticblock_select items example = block1,block2,block3...
如何让它返回所选值?
答案 0 :(得分:0)
好吧,您需要为该select元素创建自己的Store Config Dropdown类。 我建议阅读本文,有详细说明如何做到: Link to Custom Store Config settings
特别检查这部分:
<?php
class JR_CustomConfigExample_Model_System_Config_Source_Dropdown_Values
{
public function toOptionArray()
{
return array(
array(
'value' => 'key1',
'label' => 'Value 1',
),
array(
'value' => 'key2',
'label' => 'Value 2',
),
);
}
}
不要忘记在这部分中更改system.xml:
<source_model>adminhtml/system_config_source_yesno</source_model>
如果没有看到完整的模块文件,我可以帮助解决这个问题。希望它有所帮助,指出正确的方向。
答案 1 :(得分:0)
我找到了解决方案,就是这样:
public function toOptionArray()
{
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = 'SELECT title FROM ' . $resource->getTableName('cms/block');
$results = $readConnection->fetchAll($query);
$monarray = array();
$compt = 1;
foreach ($results as $key => $value) {
foreach ($value as $key2 => $value2) {
the solution ==> $monarray[$compt-1] = array('value'=>$value2,
'label'=>Mage::helper('extendedcontacts')->__($value2));
$compt++;
}
}
return $monarray;
}
我更改了这一行:
$monarray[$compt-1] = array('value'=>$compt,'label'=>Mage::helper('extendedcontacts')->__($value2));
到这一行:
$monarray[$compt-1] = array('value'=>$value2,'label'=>Mage::helper('extendedcontacts')->__($value2));
并以结果为例返回页脚链接:
array (size=8)
'excontactusSelect' => string '1' (length=1)
'staticblockSelect' => string 'Footer Links' (length=12)
'contactfrmSelect' => string '1' (length=1)
'defaultrecipientText' => string 'soufiane.marar1@gmail.com' (length=25)
'emailsenderSelect' => string 'general' (length=7)
'sendcopytosenderSelect' => string '0' (length=1)
'emailtemplateSelect' => string 'extcontacts_extendedcontactsGroup_emailtemplateSelect' (length=53)
'departementsTextarea' => string '' (length=0)
这是模块conf: http://i.stack.imgur.com/tlBfa.png