Magento - 获取自定义Widget的所有选项

时间:2011-06-01 09:15:10

标签: magento

我开始开发Magento自定义小部件,我已经为我的第一个Widget创建了这个自定义选项:

<text1>
    <label>Text 1</label>
    <visible>1</visible>
    <required>1</required>
    <type>text</type>
</text1>

<text2>
    <label>Text 2</label>
    <visible>1</visible>
    <required>1</required>
    <type>text</type>
</text2>

使用此功能,我获得了我的第一个文本值

protected function _getText1() {
    $text1 = $this->getData('text1');
    if( trim( $text1 ) != "" ){
        return $text1;
    }
}

我想知道如何只在一个函数中获取所有选项(文本字段值)(例如,使用数组)。

非常感谢:)

1 个答案:

答案 0 :(得分:2)

作为数组

public function getTextValuesOfMyWidget(){
    $textValuesByKey = array();
    foreach($this->getData() as $key => $value){
        $textValuesByKey[$key] = $value->getYourValueField();
    }
    return $textValuesByKey;
}

$this->getData(); // it already returns you all values as an array