I have a CakePHP 3.3.14 application where I've created 2 subdirectories, webroot/data/downloads/
and webroot/data/master
I want to put these paths in a custom configuration file and reference them in a Controller. But I can't see how to do this.
I've followed the documentation on Configuration but it's not very clear.
So what I've done:
- Created
config/my_config.php
The above file defines an array:
return [ 'downloadsPath' => 'webroot/data/downloads/', 'masterPath' => 'webroot/data/master/' ];
In
config/bootstrap.php
I've put:Configure::load('my_config', 'default');
How do I then use this in a Controller? If I put Configure::read('my_config.masterPath');
it gives an error saying: Class 'App\Controller\Configure' not found
If I add use Cake\Core\Configure;
to the top of my Controller, that clears the error but the return value is null
:
debug(Configure::read('my_config.masterPath')); // null
'my_config.masterPath'
no idea from where you've got the idea that you have to put the file name in front.masterPath
should work. – AntiheromasterPath
that would surely present some problem? Thanks for the advice though, I can see the error of my ways.. – Arsenic