Joomla 2.5从一个字段中获取选项(列表)

时间:2013-11-20 11:13:51

标签: list joomla joomla2.5 field options

我无法相信我会问这样的问题。我在谷歌上搜索了4个小时才找到解决方案。我找到了大约10000页关于如何在xml中创建一个字段但没有关于如何在php代码中调用选项的任何人。

我想要的是这个领域的一系列选项:

<field name="field8" type="jevcflist" default="-1" label="Alter" required="1" allowoverride="0" filter="1" access="0" size="1" style="min-width: 123px;">
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
</field>

我试过

$form = &JForm::getInstance('customfields', $xmlfile);
// get the age list                    
$field = $form->getField('field8');

当我var_dump $field的数据时:

object(JFormFieldJevcflist)[428]
  protected 'node' => null
  protected 'type' => string 'List' (length=4)
  protected 'description' => string '' (length=0)
  protected 'element' => 
    object(JXMLElement)[427]
      public '@attributes' => 
        array (size=11)
          'name' => string 'field8' (length=6)
          'type' => string 'jevcflist' (length=9)
          'default' => string '-1' (length=2)
          'label' => string 'Alter' (length=5)
          'required' => string '1' (length=1)
          'allowoverride' => string '0' (length=1)
          'filter' => string '1' (length=1)
          'access' => string '0' (length=1)
          'size' => string '1' (length=1)
          'style' => string 'min-width: 123px;' (length=17)
          'class' => string 'required' (length=8)
      public 'option' => 
        array (size=10)
          0 => string '3' (length=11)
          1 => string '4' (length=11)
          2 => string '5' (length=11)
          3 => string '6' (length=11)

所以我尝试使用$field->element->option,但它根本不起作用。 我也应该有选项价值...... 它在1.5中使用了 JParameter 但是如何在2.5中完成?

编辑: 我需要在过滤文件中使用它。

谢谢...

EDIT2: 按要求提供Joomla 1.5的代码:

$hasage = false;

        $params = new JParameter(null, $xmlfile);

        foreach($params->_xml["_default"]->children() as $n) {
            if($n->_attributes['label']=="Alter") {
                $hasage = true;
                //foreach($n->children() as $param){
                foreach($n->_children as $param){
                    $options[] = JHTML::_('select.option',
                         $param->_attributes['value'], 
                         $param->_data, //"Ab ".$param->_attributes['value']." Jahren",
                         "value",
                         "customfieldage");
                }
            }
        }

        if (!$hasage){
            $filterList["title"] = "";
            $filterList["html"] = "";
            return $filterList;
        }

        /*for($i = 3; $i < 13; $i++) {
            $options[] = JHTML::_('select.option', $i, "Ab ".$i." Jahren", "value", "customfieldage");
        }*/

        $filterList["html"] = JHTML::_('select.genericlist',
                                $options,
                                $this->filterType.'_fv',
                                'onchange="this.form.submit();"',
                                'value',
                                'customfieldage',
                                $this->filter_value);



        $script = "JeventsFilters.filters.push({id:'".$this->filterType."_fv', value:-1});";
        $document = JFactory::getDocument();
        $document->addScriptDeclaration($script);

        return $filterList;

0 个答案:

没有答案