在JFormField中访问自定义字段的自定义属性

时间:2012-06-22 17:57:06

标签: php joomla joomla2.5

我在Joomla中创建了一个自定义字段类型,需要将参数传递给它。例如,我的JForm XML文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset addfieldpath="/administrator/components/com_gallery/models/fields">

        <field name="images" 
            type="MultiImage"                         
                    label="Images"
            description="" 

            imagetable="#__gallery_images" 
            imagedir="../images/gallery/originals/"                        

                /> 

    </fieldset>

</form>

我想访问自定义字段中的imagetableimagedir属性:

<?php
// No direct access to this file
defined('_JEXEC') or die;

jimport('joomla.form.formfield');

class JFormFieldMultiImage extends JFormField
{
    protected $type = 'MultiImage';

    public function getInput() {

        //this is where i want to access it
        $input = $this->imagetable;     

        return $input;
    }
}

我认为您刚刚使用了$this->attributename,当我var_dump($this)时,我可以看到属性已定义,但它们是:protected

我希望得到一些帮助:)

谢谢, 汤姆

1 个答案:

答案 0 :(得分:6)

你真是太近了!尝试这个,让我知道它是否适合你,因为它适合我。 (Joomla 2.5.6)

echo $this->element['imagedir'];
echo $this->element['imagetable'];