CodeIgniter Forums
how to access config items - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: how to access config items (/showthread.php?tid=61916)



how to access config items - cupboy - 05-30-2015

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?

<?php
// 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');    
?>


RE: how to access config items - gadelat - 05-31-2015

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


RE: how to access config items - CroNiX - 05-31-2015

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.


RE: how to access config items - includebeer - 05-31-2015

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

See: http://www.codeigniter.com/userguide3/general/cli.html