How to make it available in every function? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to make it available in every function? (/showthread.php?tid=49774) |
How to make it available in every function? - El Forum - 03-02-2012 [eluser]CocoMansur[/eluser] Hi, i have a model that retrieves data from a database and was returned to a variable in the controller then will be displayed in view. my problem is, in every function within the controller i always have to call that model. is there a way that will do this in default without calling the model on each of the functions within the controller? here is a sample code: Code: class Base extends CI_Controller{ How to make it available in every function? - El Forum - 03-03-2012 [eluser]solid9[/eluser] try putting the code in __construct() How to make it available in every function? - El Forum - 03-03-2012 [eluser]CocoMansur[/eluser] I tried that already but it doesn't work. when i load my default page it displays, undefined variable get_latest. here is the code with the construct Code: class Base extends CI_Controller{ How to make it available in every function? - El Forum - 03-03-2012 [eluser]solid9[/eluser] try this, Code: class Base extends CI_Controller{ How to make it available in every function? - El Forum - 03-04-2012 [eluser]CocoMansur[/eluser] Thanks solid9. it worked perfectly. now, i just have to modify some of the codes. |