• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie question - global variable in codeigniter

#1
[eluser]Đỗ Thanh Tùng[/eluser]
Hi all, I'm a newbie. I have a problem when using variable in CodeIgniter.
I have a class like this :
Code:
Class abc Extends Controller {
    function abc () {
        parent::controller();
    }
    function a () {
        $this->something = 'something';
    }
    function b () {
        echo $this->something;
    }
}
when I run the function b like this : localhost/index.php/abc/a then localhost/index.php/abc/b
It return empty. How can I reuse the variable without send it's param again ?
Thanks for help.

#2
[eluser]Đỗ Thanh Tùng[/eluser]
Can anybody show me how to use a global variable that I can use in both function a and b ?

#3
[eluser]Đỗ Thanh Tùng[/eluser]
I need something like this
http://ellislab.com/forums/viewthread/80719/
Need a real example.

#4
[eluser]Pascal Kriete[/eluser]
The variable is only set for one request. Have you looked into using sessions?

#5
[eluser]Đỗ Thanh Tùng[/eluser]
Thanks inparo.
I think using session is not the correct way but that is the simplest way can fix my problem now.
Thanks a lot.

#6
[eluser]Senthilguru[/eluser]
Global variable Declaration..
declare it in config file : location.... system/application/config/config.php

Code:
$config['site_name'] =   'XXXXXXXXXXXXXXXXXXXX';

get anywhere like this....

Code:
$this->config->item('site_name');



Cheers,
Senthilguru.E
www.cogzidel.in


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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