Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define variable in cakephp which is accessible throughout the application?

Tags:

cakephp

I want to define a variable in cakephp that can be accessed from anywhere (i.e model,controller,component etc.) without using session. How to achieve this in cakephp, any suggestion?

like image 537
Vikramraj Avatar asked Dec 04 '25 22:12

Vikramraj


1 Answers

You could define constants in app/Config/bootstrap.php, but a better solution would be use Configure::write();

For example if you want read some variable anywhere, you can set it in bootstrap.php file (app/Config/) or in Your AppController.php (app/Controllers) by:

Configure::write('variable_name', 'variable_value');

and read it anywhere by:

Configure::read('variable_name');
like image 119
kicaj Avatar answered Dec 07 '25 05:12

kicaj