So I tried to create a library in which I can get some "global" data from one of my data tables (site name, logo, favicon, etc).
This is my current library:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Settings {
//holds the CI instance
//var $ci;
protected $ci;
//the array the settings will be stored as
public $settings = array();
//
public function __construct()
{
//load CI instance
$this->ci =& get_instance();
//fire the method loading the data
$this->get_settings();
}
public function get_settings()
{
$this->ci->load->model('settings_model');
$this->settings = $this->ci->Settings_model->get_list();
return $this->settings;
}
}
?>
This library should access to my method get_list() on my Settings_model and so far it seems to be able to do so (keep reading).
This is my settings model:
function __construct()
{
parent::__construct();
$this->table = 'ci_settings';
}
public function get_list()
{
$query = $this->db->get($this->table);
return $query->result();
}
Now to use the data which comes from the database in my views without having to declare them in all my controllers, I just have to do this(I did something similar with my menu library so I know it should work):
<?php echo $this->settings['website_name'] ?>
Here is the PROBLEM, my library is being able to access to my model which seems fine(I suppose), the problem comes when it tries to access to the get_list method itself; is apparently having some issues returning the data as this is the error that I get:
Should not this be possible just like this?.. what I'm trying is to have global variable for logo, website name, etc... I'm sure it should not be that hard but I'm having a really big pain in the *** trying to figure out a solution.
Any idea where is my error?, Thanks in advance.