我正在使用joomla 2.5,我想创建一个自定义表单字段类型that stored in the same module.
在XML中:
<fieldset name="basic" addfieldpath="/modules/mod_royalslider/fields"></fields>
<fieldset name="basic">
<field name="title" type="City" label="anythging" description="" />
</fieldset>
</fields>
在档案/modules/mod_royalslider/fields/city.php
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
jimport('joomla.form.formfield');
class JFormFieldCity extends JFormField {
protected $type = 'City';
// getLabel() left out
public function getInput() {
return '<select id="'.$this->id.'" name="'.$this->name.'">'.
'<option value="1" >New York</option>'.
'<option value="2" >Chicago</option>'.
'<option value="3" >San Francisco</option>'.
'</select>';
}
}
现在它显示我的错误,当我删除
<fieldset name="basic" addfieldpath="/modules/mod_royalslider/fields"></fields>
错误消失,字段显示为文本字段。
答案 0 :(得分:12)
您忘记在addfieldpath
<fields name="params">
<fieldset name="basic" addfieldpath="/modules/mod_royalslider/models/fields">
<field name="title" type="City" label="anythging" description="" />
</fieldset>
</fields>
只需将fields文件夹放在models文件夹中,然后像上面那样放置路径。
答案 1 :(得分:1)
您只需使用您提供的代码即可:
<fields>
<fieldset name="basic" addfieldpath="/modules/mod_royalslider/fields">
<field name="title" type="City" label="anythging" description="" />
</fieldset>
</fields>
答案 2 :(得分:1)
在字段中使用addfieldpath
,如::
<fields name="params" addfieldpath="/modules/mod_royalslider/models/fields" >
<fieldset name="basic">
<field name="title" type="City" label="anything" description="" />
</fieldset>
</fields>
答案 3 :(得分:-1)
您可以尝试使用此代码。我的这项工作
<fieldset addfieldpath="/modules/mod_royalslider/models/fields" name="basic">
<field name="title" type="City" label="anything" description="" />
</fieldset>