CodeIgniter Forums
db not appearing in module. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: db not appearing in module. (/showthread.php?tid=78435)



db not appearing in module. - richb201 - 01-19-2021

$this->db->set('campaign'$campaign);  //set the last campaign used

I am autoloading database.php and all is OK. I have another module that is being spawned by koolreports render() command. In it I have no access to $this. So when I try to access the db from it $this->db fails. I was having the same issue with sessions. Someone up here recommended using:

$CI = & get_instance();
$CI->load->model('MyModel')->library('session');
$this->MyModel = $CI->MyModel;
$this->session = $CI->session;


which worked great. 

Any idea how i can get analagous access to the db (which is already open) in another module? 


RE: db not appearing in module. - InsiteFX - 01-20-2021

There you go again with the small font size.


RE: db not appearing in module. - richb201 - 01-20-2021

Sorry. I fixed that. At this point I have changed my mind and am not planning to keep the last year "run". I am still having an issue with this module, however. I can't seem to get the form to respond right away. Rather, it is delayed until after i press submit again.


RE: db not appearing in module. - iRedds - 01-21-2021

If you use the autoload config to connect to the database ($autoload['libraries'] = array('database')).
Then just define the db property

$this->db = $CI->db;

Else add initialization

$CI->load->model('MyModel')->library('session')->database();