Joomla - dynamic dropdown list in admin panel

2019-04-13 02:47发布

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.

3条回答
手持菜刀,她持情操
2楼-- · 2019-04-13 03:21

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 );
    }

}

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-13 03:42

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.

查看更多
Evening l夕情丶
4楼-- · 2019-04-13 03:48

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

查看更多
登录 后发表回答