Global variable in CI |
[eluser]anishpsla[/eluser]
Is it possible to add global variable to CI ? For example, I want to use some parameter like site name to all page titles. Making it available all over the application will help.
[eluser]Tpojka[/eluser]
There is more then one way you can do that. On my mind are two immediatelly: 1. save it in - application/constants.php 2. Declare variable in core/MY_Controller.php Example Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]CroNiX[/eluser]
Another way is with a config file, and then autoload it. http://ellislab.com/codeigniter/user-gui...onfig.html
[eluser]ivantcholakov[/eluser]
Yet another way you may find within this discussion: http://ellislab.com/forums/viewthread/241311/
[eluser]jonez[/eluser]
If you are setting application constants I'd recommend using a config file. In my app I auto-load /config/app.php that contains constants like the application name, support email, etc. Then you can access those variables using $this->config->item( 'name' ). If they are true constants I'd add them to /config/constants.php and name them in all uppercase like the others.
[eluser]anishpsla[/eluser]
Thanks friends, thanks for your valuable info. Now I know how to set Global variables in CI. |
Welcome Guest, Not a member yet? Register Sign In |