Problem with both Menu and SQL field types.

58 views
Skip to first unread message

darrenf...@gmail.com

unread,
Jan 24, 2023, 1:26:38 AM1/24/23
to Joomla! General Development
Hi,

I've tried using the standard Menu and SQL field types.

I've used the following XML code for the field

<field name="menu" type="menu" label="Menu" description="Select menu items to show"></field>

<field name="menu" type="sql" label="Menu" description="Select menu item to show" query="SELECT id as key, title as value FROM #__menu_types ORDER title ASC"></field>

I'm using it with the Joomlart ACM module in Joomla 4 in my template.

On both occasions I get the similar error back

Database not set in Joomla\CMS\Form\Field\MenuField
Database not set in Joomla\CMS\Form\Field\SQLField

I looked on github at the code in Joomla\CMS\Form\Field\MenuField and SQLField and the only thing I can see is $db = $this->getDatabase () ; referring to the database.

I believe something changed regarding the way joomla access the database now in Joomla 4?  I presume that's what is causing the issue?  Is the error in Joomlarts ACM module or Joomla 4 itself - all I can tell is that Joomlarts ACM module just seems to take the field XML information and uses it with Joomlafield anyway so I can't see it being an issue on their end.

I would make my own custom field but not sure where I'd put custom field code in a template and call the SQL myself through PHP (can you even define a custom field in a template?)

Peter Tuson

unread,
Jan 27, 2023, 4:25:46 AM1/27/23
to Joomla! General Development
I have never seen this error in Joomla 3 or 4. I would raise it with Joomlart.

Peter.

Mark Fleeson

unread,
Feb 9, 2023, 7:13:55 AM2/9/23
to Joomla! General Development
What version of Joomla 4 are you using, $this->getDatabase can only be used since Joomla 4.2 and then only in models.
Outside of these the following command is recommended
$db = Factory::getContainer()->get('DatabaseDriver');

Mark

darrenf...@gmail.com

unread,
Feb 10, 2023, 3:47:49 AM2/10/23
to Joomla! General Development
Thanks Mark,

seems to be an issue with the way Joomlart do stuff in their module!  Joomlart stuff can be good but I do notice that they don't always follow the standard joomla conventions!!

Reply all
Reply to author
Forward
0 new messages