Closed benediktblank closed 1 year ago
Sorry, this was a docs bug. You can control DB logging by setting the yii\db\Connection::$enableLogging
property directly in config/app.php
:
return [
'components' => [
'db' => function() {
$config = craft\helpers\App::dbConfig();
// Always enable DB logging (by default it would only be enabled for Dev Mode)
$config['enableLogging'] = true;
return Craft::createObject($config);
},
],
];
@brandonkelly
Wait, so I gotta move my complete DB config from db.php to app.php for this to work?
When I just add what you provided I still get an error saying: "The configuration for the "db" component must contain a "class" element."
When I provide that like that:
'components' => [
'db' => [
'class' => '\yii\db\Connection',
'enableLogging' => App::env('ENVIRONMENT') === 'dev'
]
it wants dsn element and so on: "Connection::dsn cannot be empty."
There is no mention about in the 4.X db documentation either: https://craftcms.com/docs/4.x/config/db.html
You don’t need to make any changes to your DB configuration in config/db.php
(besides removing the enableLogging
setting that shouldn’t have been added there in the first place).
And sorry, my original db
component config example was bad. You should be setting it to a closure that calls craft\helpers\App::dbConfig()
, modifies the resulting config, and then returns an object created from it. I’ve updated the example above.
No need to override the class
property. (Craft actually uses its own connection class that extends yii\db\Connection
, and class
will already be set within the $config
array returned by craft\helpers\App::dbConfig()
.)
The docs still show the incorrect information, can they be updated with a working example?
@ericdrosas87 What is incorrect?
@brandonkelly The documentation for v4.X
still shows that the all that needs to be added to app.php
are the two key-values. Which still produces the Exception 'yii\base\InvalidConfigException' with message 'The configuration for the "db" component must contain a "class" element.'
error message. According to your response above though an anonymous function needs to be passed in instead?
@ericdrosas87 Doh, thanks! Fixed now: https://craftcms.com/docs/4.x/upgrade.html#logging
@ericdrosas87 Doh, thanks! Fixed now: https://craftcms.com/docs/4.x/upgrade.html#logging
Excellent - thank you for updating that!
What happened?
Description
enableLogging is still mentioned here: https://craftcms.com/docs/4.x/upgrade.html#logging
It's linking to this page: https://craftcms.com/docs/4.x/config/db.html#enablelogging
But there's nothing there. And when I add that config, I get a fatal error.
Steps to reproduce
Expected behavior
The config that is documented works
Actual behavior
Craft crashes
Craft CMS version
4.2.3
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
-