【问题标题】:Joomla 3 custom field get xml fieldJoomla 3自定义字段获取xml字段
【发布时间】:2014-09-15 13:12:54
【问题描述】:

我正在创建一个自定义字段来创建一个输入图像数组作为媒体类型。

我怎样才能恢复类型为 media 的输入数组?

class JFormFieldimglist extends JFormField {

        //The field class must know its own type through the variable $type.
        protected $type = 'imglist';

        public function getLabel() {
                return "List Image";
        }

        public function getInput() {
          for ($i = 1; $i <= 10; $i++) {
          $images.= '<input type="text" value="'.$this->value[$i].'" name="'.$this->name.'['.$i.']" />';            
          }
             return $images;
        }
}

从xml我用这个

<field name = "myimage" type = "media" directory = "stories" />

【问题讨论】:

    标签: joomla3.0 joomla3.3


    【解决方案1】:

    有两个问题。第一个问题是您扩展核心 JFormField 类。第二个问题是媒体字段类型实际上是一个模态表单字段。这是一种特殊的字段,用于在模态窗口中呈现更复杂的界面供用户选择。例如,当您为菜单类型单篇文章选择文章,或单击位于所见即所得编辑器下方的图像按钮时。

    我的猜测是您想从特定文件夹中提取图像列表,供用户从下拉列表中选择。在下面的示例中,请注意我完全省略了 getLabel() 和 getInput() 方法并添加了 getOptions()。原因是通过扩展 JFormFieldList 类,这些方法已经构建出来,不需要特殊要求。您只需重写 getOptions() 方法即可为核心类提供您希望在该字段中显示的选项列表。

    jimport('joomla.form.helper');
    JFormHelper::loadFieldClass('list');
    
    class JFormFieldimglist extends JFormFieldList {
    
        //The field class must know its own type through the variable $type.
        protected $type = 'imglist';
    
        public function getOptions() {
            // build out your options array
            // You should format as array, with full path as key and 
            // human readable as value
            $options = array('/images/flowers/tulip.png' => 'Tulip');
            return $options;
        }
    }
    

    这里有一些链接可以扩展我的帖子。

    http://docs.joomla.org/Creating_a_custom_form_field_type http://docs.joomla.org/List_form_field_type http://docs.joomla.org/Creating_a_modal_form_field

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-08
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      相关资源
      最近更新 更多