0

我在 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...

我该怎么做才能让它返回选定的值?

4

2 回答 2

0

好吧,您需要为该选择元素创建自己的 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>

如果看不到您的完整模块文件,我可以帮助解决这个问题。希望它有所帮助,指出正确的方向。

于 2014-02-13T23:07:35.193 回答
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)

这是模块配置:http: //i.stack.imgur.com/tlBfa.png

于 2014-02-14T12:15:14.303 回答