Search code examples
databasejoomlacontactsdbojoomla-jtable

How to access contacts in Joomla via JTable?


Still working on my component, I am currently trying to add, edit and delete contacts. I found them to be located in contact_details. Accessing them using JFactory::getDBO() is working. The documentation says, using JTable is more safe and the intended way to work with the database.

Using JTable::getInstance('contact_details') leads to an error saying, 'contact_details' is not supported. Is there a way to access the contact_details using JTable? Would I have to create a custom table in order to make it work?

Thanks in advance!


Solution

  • The argument of JTable::getInstance() is not the name of the database table it is the name of the table class. In this case if you looked in /administrator/components/com_contant/tables you would see that the table class name ins ContactTableContact which is the conventional pattern for tables in Joomla! where the first table gives the location (the API will strip off the com_ the second says it is a table class and in either the table or tables folder (the latter is legacy) and the last segment is the name of the file. So JTable::getInstance('ContactTableContact') should do the trick for you.