CodeIgniter Forums
Newbie question - global variable in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Newbie question - global variable in codeigniter (/showthread.php?tid=12414)



Newbie question - global variable in codeigniter - El Forum - 10-18-2008

[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.


Newbie question - global variable in codeigniter - El Forum - 10-18-2008

[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 ?


Newbie question - global variable in codeigniter - El Forum - 10-18-2008

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


Newbie question - global variable in codeigniter - El Forum - 10-18-2008

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


Newbie question - global variable in codeigniter - El Forum - 10-18-2008

[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.


Newbie question - global variable in codeigniter - El Forum - 10-18-2008

[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