CodeIgniter Forums

Full Version: how to access config items
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I tried this. It fails.

Trying to access items I have added to
application/config/config.php within a cronjob
Maybe this is just something that can't be done?

// include './lib/inc_dbconnect.php';
// Database Connections

// the below fails:

//$db_host     = $this->config->item('db_host');
//$db_database = $this->config->item('db_database');
//$db_username = $this->config->item('db_username');
//$db_password = $this->config->item('db_password');    

// the below fails also:

$db_host     = config_item('db_host');
$db_database = config_item('db_database');
$db_username = config_item('db_username');
$db_password = config_item('db_password');    
1. database settings should be in database.php config
2. config items should be loaded from within controller/model
3. database should be initialized using $this->load->database('group_name'); if you need to do it manually
If your cronjob is calling a CONTROLLER, that won't be an issue. But from the limited code you provided, it does not look like a CI Controller. It looks like something totally outside of CI, so CI methods/objects won't be present.
As always, the user guide is your friend. Create a controller, then call it from your cronjob. That way you'll have access to everything CodeIgniter provides (database connection, configuration etc).