Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CodeIgniter, where should I declare my global variables?

I want to declare some global variables and global constants. Normally, I would put them in the includes/global.php of my own custom framework.

Where should I define globals in CodeIgniter? Here's an example of the globals I want to declare:

define('USERSTAT_OFFLINE', 0);
define('USERSTAT_ONLINE', 1);
define('USERSTAT_AWAY', 2);
define('USERSTAT_BUSY', 3);

$PAYMENT_PLANS = array();
$PAYMENT_PLANS[] = array('id'=>1, 'name'=>'Trial');
$PAYMENT_PLANS[] = array('id'=>2, 'name'=>'Premium Plan');
like image 668
John Avatar asked Nov 04 '09 05:11

John


People also ask

Where should global variables be declared?

Hence, the natural place to put global variable declaration statements is before any function definitions: i.e., right at the beginning of the program. Global variables declarations can be used to initialize such variables, in the regular manner.

How declare variable in PHP CodeIgniter?

In CodeIgniter 4, we have a folder like app/config/Constant. php so you can define a global variable inside the Constant. php file.

Where do you use global variables?

Global variables can be used by everyone, both inside of functions and outside.


1 Answers

You may utilise config file (system/application/config/config.php) to set configuration related variables.

Or use constant file (system/application/config/constants.php) to store site preference constants.

like image 153
Trav L Avatar answered Sep 25 '22 20:09

Trav L