Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catalyst application-wide variable

I would like to be able to define an application-wide (global) variable in my Catalyst application so that I can access it in any controller I am in. The purpose for this is that I'm not repeating values around my app that for the most part never change. Currently I am defining variables in my_app.pm like so:

our $GLOBAL_VAR = 'value';

And then in my controllers, I try to access the variable just like I would a subroutine:

my_app::$GLOBAL_VAR

However, this does not work. Does anyone know the best way to do this, or a better way to achieve this in Catalyst? Thanks!

like image 431
srchulo Avatar asked Jul 06 '26 16:07

srchulo


1 Answers

To access such a global variable here is the right syntax:

say $my_app::GLOBAL_VAR;
like image 115
user1126070 Avatar answered Jul 09 '26 07:07

user1126070



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!