load variables in config file - 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: load variables in config file (/showthread.php?tid=2129) |
load variables in config file - El Forum - 07-17-2007 [eluser]Aaron L.[/eluser] Hi There, I am trying to integrate a 3rd party API with CI and so far everything is going pretty well. There is one hang-up that I am running into however: In order to run the API, I have to send it some configuration settings. The api is accessed from multiple controllers, and so I have decided to create a separate file in /config which contains these variables and then include it in these controllers. Here is an example of what I have so far: /application/config/api_config.php: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Here is a function within controller which uses (includes) the variables above: /application/controllers/apicontroller.php Code: function something() The problem I am having is that it seems like the $config variables are not being passed along to my controller. Any ideas? Aaron load variables in config file - El Forum - 07-17-2007 [eluser]Aaron L.[/eluser] Is using PHP's require() function OK? load variables in config file - El Forum - 07-18-2007 [eluser]Bulk[/eluser] You're not quite using the config system in the correct way... Firstly, if your config file is indeed named api_config.php you'll need a line similar to: Code: $this->load->config('api_config'); Then to access values from any config file (the main one, or yours) you would use this syntax: Code: $this->config->item('sendToProduction') Be sure to read the user guide for more information. load variables in config file - El Forum - 07-18-2007 [eluser]Aaron L.[/eluser] Thanks for your help, Bulk. I will give it a shot this way. |