CodeIgnator global variable scope and uses

In this tutorial we are going to see the scope of global variable there will be available on anywhere and hold the information as you wants.

see below some step to make the global variable.

  • Create the file inside the application/libraries folder.
  • create a new file in /application/config with same name as given in application/libraries and declare your global variables in it.
  • Create your own file in application/core and declare the global variables in it.
  • Create the Global variable suppose the Global Variables are true constants, just add them in
  • application/config/constants.php file and name them in all uppercase like the others are defined.
  • If you want to set application constants create new config file and add the variables. Now load it as $this->config->load(‘file_name’); And access those variables as $this->config->item(‘variable_name’); .
    inside the application/libraries create the file called global.php see below code.

libraries ..

now inside the config file create the variable like

Config file..

inside the autoload.php declare the file name like

autoload.php..

Now we are just check the variable is available in anywhere so will make it controller and view file for displaying the variable.

Global_Variable_CI.php..

global_variables_ci.php file is view file we need just print that variable and confirm that exists anywhere.

global_variables_ci.php..