• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pls help

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.

Quite a few ways to do this:

If it just one controller then just put your variables at the top something like this:
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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.