CakePHP 4 Using an app.php or app_local.php Variable in Components or Controllers
CakePHP 4 Using an app.php or app_local.php Variable in Components or Controllers
In your controller, add the following to access the configuration settings:
use Cake\Core\Configure;
Set your variable value in app.php or app_local.php
return [ ... 'MyConfig' => [ 'userid' => env('MYCONFIG_USERID', 'EXAMPLEUSERID'), 'password' => env('MYCONFIG_PASSWORD', 'EXAMPLEPASSWORD'), ], ... ];
Then, you can read the variables, like the following example:
$userid = Configure::read('Myconfig.userid'); $password = Configure::read('Myconfig.password');