Welcome Guest, Not a member yet? Register   Sign In
pls help
#1

[eluser]newbie110[/eluser]
I am having a couple of common variables which are being shown on each view page, for that I have to load these variables in each function of the controller. Is there any way to globally load them so that I don't have to copy the same code again and again.
#2

[eluser]Otemu[/eluser]
Quite a few ways to do this:

If it just one controller then just put your variables at the top something like this:
Code:
class MyGlobalVariables extends CI_Controller{

$myVariable = 'hi am a global variable';

  function someCoolFunction(){
      
     echo $this->myVariable ;
  }
  function someOtherCoolFunction(){
      
     echo $this->myVariable ;
  }
}
Create your variables within My_Controller have it extend CI_Controller, then instead of using class myGlobalVariables extends CI_Controller you would have myGlobalVariables extends My_Controller.
Create a library
Simple method would be just to save your variables in the config
You could use constants \application\config\constants.php




Theme © iAndrew 2016 - Forum software by © MyBB