[eluser]CroNiX[/eluser]
Well, I assume you are autoloading your library in your autoload.php config file.
If so, then in your controllers you just access it like:
$this->global_lib->some_method();
or $some_param = $this->global_lib->function_that_returns_something($some_var);
or $some_param = $this->global_lib->some_public_var_of_lib_object;
I would write your library like:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Global_lib {
private $CI; //we will access CI from this var
public $site_theme = 'theme_path'; //default value
public $user_theme = 'user selected theme'; //default value
public function __construct()
{
$this->CI =& get_instance();
log_message('debug', 'Global_lib: Loaded');
}
//some setters
public function set_theme($theme)
{
$this->site_theme = $theme;
}
public function set_user_theme($theme)
{
$this->user_theme = $theme;
}
//a getter
public function get_globals()
{
return array('site_theme' => $this->site_theme, 'user_theme' => $this->user_theme);
}
public function fetch_theme()
{
//maybe fetch the theme for the current user from the database?
$theme = $this->CI->db
->select('code')
->where('theme_name', $this->user_theme)
->get('theme_table')
->result_array();
return $theme;
}
}
Then, in your controller, you just
Code:
$settings = $this->global_lib->get_globals();
echo $settings['user_theme'];
// echos "user selected theme"
$this->global_lib->set_user_theme('new theme');
echo $this->global_lib->user_theme; //echos "new theme";
$data['theme'] = $this->global_lib->fetch_theme();
//load the view with our theme data
$this->load->view('admin/some_viewfile', $data);
Hope it gives you some ideas.