Welcome Guest, Not a member yet? Register   Sign In
how to access config items
#1

(This post was last modified: 05-30-2015, 05:36 PM by cupboy.)

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');    
?>
Reply
#2

(This post was last modified: 05-31-2015, 01:29 AM by gadelat.)

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
Reply
#3

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.
Reply
#4

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
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB