我有一个 CakePHP 3.3.14 应用程序,我在其中创建了 2 个子目录,webroot/data/downloads/
并且webroot/data/master
我想将这些路径放在自定义配置文件中并在 Controller 中引用它们。但我看不出如何做到这一点。
我遵循了有关配置的文档,但不是很清楚。
所以我做了什么:
- 已创建
config/my_config.php
上面的文件定义了一个数组:
return [ 'downloadsPath' => 'webroot/data/downloads/', 'masterPath' => 'webroot/data/master/' ];
在
config/bootstrap.php
我放:Configure::load('my_config', 'default');
然后我如何在控制器中使用它?如果我把Configure::read('my_config.masterPath');
它给出一个错误说:Class 'App\Controller\Configure' not found
如果我添加use Cake\Core\Configure;
到控制器的顶部,则会清除错误,但返回值为null
:
debug(Configure::read('my_config.masterPath')); // null