I can’t read Configure::read(‘Datasources.default’), is resolves to null. I can read, for instance , Configure::read(‘debug’).
When I change the ‘Datasources’ name to ‘Datasources1’ , then Configure::read(‘Datasources1.default’) resolves to a nicely filled array …
When I first do a Configure::load(‘app_local’, ‘default’) then I can Configure::read(‘Datasources.default’).
What is wrong with the ‘Datasources’ name or why is it not loaded?
In bootstrap.php Configure::load(‘app_local’, ‘default’) is loaded.
bizdev
July 23, 2020, 10:14am
2
Hi @hessmac ,
You can read database configuration via:
use Cake\Datasource\ConnectionManager;
$connection = ConnectionManager::get('default');
Thanks bizdev, but then I have a connection and I only want to read some of the keys in ‘Datasources.default’. Is that not possilbe?
AND
why Can I read when the name is ‘Datasources1’ …?
@bizdev ,
You got me reading twice in the book I now have found that this works for me :
ConnectionManager::getConfig(‘default’);
Thank you !
Zuluru
July 23, 2020, 3:25pm
5
To answer your other question, you can’t read it from the Configuration even though it’s written there, because the creation of the datasource consumes that; it reads and removes it. This is, I assume, for security, so that some malicious bit of code has a much smaller window in which it can access things like your database credentials.
@Zuluru
That makes perfect sense, now I understand what was happening .
Thanks a lot for the info!