I'm developing my own component for Joomla but I'm beginner in PHP and don't know how to get the names of parents. I have the table #__records (for example):

id  name           parent
1   ChildName      2
2   ParentName1    0
3   ParentName2    0

and I have the field name="parent" type="list" at admin.../models/forms/record.xml. If I open the record "ChildName" at back-end for editing I see the drop-down list for choosing parent but it's empty. I need to get the names of parents i.e. "ParentName1, ParentName2" at this list. What do I need to write in admin.../models/record.php at function getItem() or somewhere else ?

1 Answer 1


Do it with SQL form field type

  label="Select parent"
  query="SELECT id, name FROM `#__records` WHERE `parent`='0'"
    <option value="">Please select parent</option>

or create a custom form field type.

With custom form field, you could show childs under parents, like category selects etc. It gives you more flexibility.

It sounds like you are doing category type thing. If so, you should use built in category manager. See Joomla! Docs: Developing a MVC Component/Adding categories on how to add categories to custom component.

  • I decided to use only one table for records and their categories in order to minimize sql-queries. What do you think about such way?
    – stckvrw
    Commented Apr 9, 2015 at 9:00
  • I wouldn't do it. It's not good to keep different type of data in one table. Go with Joomla! Category manager solution. Then you can have child categories, description etc. This avoids any possbile problems in future. I don't think it would be remarkably more time consuming. Many Joomla! core components do it like this.
    – Rene Korss
    Commented Apr 9, 2015 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.