[BUG]: Call to getDatabase in module results in error #1238
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:implements DatabaseAwareInterface
use Joomla\CMS\Factory; use Joomla\Database\DatabaseAwareInterface; use Joomla\Database\DatabaseAwareTrait;
public function __construct() {
$this->setDatabase(Factory::getContainer()->get('DatabaseDriver'));
}
Steps to reproduce the Bug
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
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 generateddata.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!