[BUG]: Call to getDatabase in module results in error #1238

Open
opened 2025-07-24 17:41:29 +00:00 by ConfidantCommunications · 2 comments

What Happened?

I'm using JCB 5.1.1 and developing a module right now. I am using a custom get. It appears in the data.php when I compile, and it uses a call to $db = $this->getDatabase();. This fails, reporting getDatabase is not a function. If I manually edit the class in data.php with these things the database works:

  1. implements DatabaseAwareInterface
  2. use Joomla\CMS\Factory; use Joomla\Database\DatabaseAwareInterface; use Joomla\Database\DatabaseAwareTrait;
  3. public function __construct() {
    $this->setDatabase(Factory::getContainer()->get('DatabaseDriver'));
    }

Steps to reproduce the Bug

  1. Create a custom get by duplicating a dynamic get and setting to getCustom or getCustoms type.
  2. Create a module which uses the custom get under the Code tab.
  3. Add code that creates an instance of the data class, and attempts to call the custom get method on it.
  4. Compile and install. It will show an error on module execution.

Which Joomla version are you compiling in?

5.3.2

Which PHP version are you compiling in?

8.2.23

Which Joomla versions are you targeting?

5

Which PHP version are you targeting?

8.2.23

Which Web server is JCB running on?

Joomla Docker image. Apache 2

Which Relational Database is JCB running on?

mysqlnd 8.2.23

Which OS is JCB running on?

Alpine linux

Which JCB version are you using?

5.1.1

Where in JCB did this issue occur?

Other

On which browsers did you encounter the issue?

Firefox, Chrome

Additional Comments

No response

### What Happened? I'm using JCB 5.1.1 and developing a module right now. I am using a custom get. It appears in the data.php when I compile, and it uses a call to `$db = $this->getDatabase();`. This fails, reporting getDatabase is not a function. If I manually edit the class in data.php with these things the database works: 1. `implements DatabaseAwareInterface` 2. `use Joomla\CMS\Factory; use Joomla\Database\DatabaseAwareInterface; use Joomla\Database\DatabaseAwareTrait;` 3. `public function __construct() {` `$this->setDatabase(Factory::getContainer()->get('DatabaseDriver'));` `}` ### Steps to reproduce the Bug 1. Create a custom get by duplicating a dynamic get and setting to getCustom or getCustoms type. 2. Create a module which uses the custom get under the Code tab. 3. Add code that creates an instance of the data class, and attempts to call the custom get method on it. 4. Compile and install. It will show an error on module execution. ### Which Joomla version are you compiling in? 5.3.2 ### Which PHP version are you compiling in? 8.2.23 ### Which Joomla versions are you targeting? 5 ### Which PHP version are you targeting? 8.2.23 ### Which Web server is JCB running on? Joomla Docker image. Apache 2 ### Which Relational Database is JCB running on? mysqlnd 8.2.23 ### Which OS is JCB running on? Alpine linux ### Which JCB version are you using? 5.1.1 ### Where in JCB did this issue occur? Other ### On which browsers did you encounter the issue? Firefox, Chrome ### Additional Comments _No response_
ConfidantCommunications added the
Bug
label 2025-07-24 17:41:29 +00:00
Owner

Thank you for taking the time to report this issue and for outlining the steps so clearly — your feedback is appreciated.

We can confirm that this behavior is known, and your observation is accurate: under certain circumstances when using custom get methods within a module, the generated data.php class lacks the necessary interface and setup to access the database via $this->getDatabase(), resulting in a fatal error.

This is currently being addressed as part of a broader refactor of the JCB module compiler, which is being brought up to Joomla 5's native architecture. The plugin area has already been migrated, and we are now completing similar improvements in the module area — including enhanced support for dependency injection, interface compliance, and overall structural alignment with Joomla 5's stricter service container usage.

Your report aligns perfectly with the work we're doing, and we will ensure this scenario is directly handled in the updated compiler logic. Once complete, JCB will generate fully compliant module code where custom gets and service access (such as database drivers) function reliably and predictably out of the box.

Thank you again for your input — community insights like yours are essential in helping us refine and future-proof the platform. We truly value your contribution and will update the changelog when this fix is fully integrated.

Thank you for taking the time to report this issue and for outlining the steps so clearly — your feedback is appreciated. We can confirm that this behavior is known, and your observation is accurate: under certain circumstances when using custom `get` methods within a module, the generated `data.php` class lacks the necessary interface and setup to access the database via `$this->getDatabase()`, resulting in a fatal error. This is currently being addressed as part of a broader **refactor of the JCB module compiler**, which is being brought up to Joomla 5's native architecture. The plugin area has already been migrated, and we are now completing similar improvements in the module area — including enhanced support for dependency injection, interface compliance, and overall structural alignment with Joomla 5's stricter service container usage. Your report aligns perfectly with the work we're doing, and we will ensure this scenario is directly handled in the updated compiler logic. Once complete, JCB will generate fully compliant module code where custom gets and service access (such as database drivers) function reliably and predictably out of the box. Thank you again for your input — community insights like yours are essential in helping us refine and future-proof the platform. We truly value your contribution and will update the changelog when this fix is fully integrated.

I appreciate the detailed response, thank you. I look forward to every new release!

I appreciate the detailed response, thank you. I look forward to every new release!
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1238
No description provided.