I have added a dropdown list to my user creation form in admin panel in Joomla! 1.5 (using .xml files). The problem I have is that the content of it must be dynamic (comes from an external source file). My question is where (and possibly how) I can make it.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
you can create your own type. At your default.xml you will have something like:
<url addpath="/administrator/components/com_componentname/elements/">
<param name="id" type="myType" default="0" label="SELECT_LABEL" description="SELECT_DESC" />
</url>
and as implementation in /administrato/components/com_componentname/elements/myType.php
class JElementmyType extends JElement {
var $_name = 'myType';
function fetchElement($name, $value, &$node, $control_name)
{
$list = READ_FILE_OR_DB_OR_ANYTHING();
array_unshift($list, JHTML::_('select.option', '0', '-'.JText::_('Select Me').' -', 'value', 'text'));
return JHTML::_('select.genericlist', $list, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name );
}
}
回答2:
You can use sql type field if you are using xml form.
<param name="user" type="sql" default="" label="Select an User" query="SELECT id, username FROM #__user" key_field="id" value_field="username" />
read more - http://docs.joomla.org/Sql_parameter_type
回答3:
I have this problem - done just like You told me, my code looks like that:
<?php
jimport( 'joomla.html.html.select' );
class JElementKlasa extends JElement {
var $_name = 'Klasa';
function fetchElement($name, $value, &$node, $control_name)
{
$list = array(1=>'a', 2=>'b');
$options = array();
foreach($list as $key=>$value)
$options[] = JHTML::_('select.option', $key, $value);
//array_unshift($list, JHTML::_('select.option', '0', "Take it"));
return JHTML::_('select.genericlist', $options, 'klas', '', 'value', 'text');
}
?>
but it does not appear there - it actually makes the space for it, but it is empty : ( I will keep trying to fix it in the meantime.