I have two methods in my model. One is selecting and returning the data to the controller (public) and the other method (private) is selecting data from the database and returning it to the public method.
This is my public method;
public function get_template()
{
// Get the active config.
$config_id = $this->get_config();
// Prepare the SQL query.
$this->db->select('template');
$this->db->from('tms_config');
$this->db->where('config_id',$config_id);
$this->db->limit(1);
// Execute the query.
$query = $this->db->get();
// Get the result.
$result = $query->row_array();
// Make sure a template is set.
if ( ! empty($result['template']))
{
return $result['template'];
}
else
{
// Return the default template.
return DEFAULT_TEMPLATE;
}
}
Then the private method.
private function get_config()
{
// Prepare the SQL query.
$this->db->select('config_id');
$this->db->from('tms_config');
$this->db->where('active',1);
$this->db->limit(1);
// Execute the query.
$query = $this->db->get();
// Get the result.
$result = $query->row_array();
// Return the configuration ID.
return $result['config_id'];
}
Apparently something is going wrong, as $config_id in the public method is empty.
This error appears;
A PHP Error was encountered
Severity: Notice
Message: Undefined index: config_id
Filename: models/tms_config.php
Line Number: 140
Line 140 is the return-line of the get_config() method.
Can anybody please help me out on this one? Thanks in advance.