Is it Allowed to Make loading of Resources Global to a controller? - 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: Is it Allowed to Make loading of Resources Global to a controller? (/showthread.php?tid=2086) |
Is it Allowed to Make loading of Resources Global to a controller? - El Forum - 07-15-2007 [eluser]n00bPhpCoder[/eluser] instead of loading them via functions can we do this? say function index(){ $this->load->model('downloadmodel','dl'); $data['downloads']=$this->dl->getEntries(2); $this->load->view('home',$data); } instead of loading the model in index function i need to load it globally so that other functions can use the model too. like can i load it on constructor function Home() { parent::Controller(); $this->load->model('downloadmodel','dl'); } so that the model object is also available on other functions? function no1{ $this->dl->something } function no2{ $this->dl->something } Any Ideas? Is it Allowed to Make loading of Resources Global to a controller? - El Forum - 07-15-2007 [eluser]Derek Allard[/eluser] Currently models cannot be autoloaded, but it does seem like that would be useful. Is it Allowed to Make loading of Resources Global to a controller? - El Forum - 07-15-2007 [eluser]n00bPhpCoder[/eluser] Right i was still thinking of Windows Programming . Im a bit new to CI so if ever my ways is not right pls correct me. BTW, does CI auto unload objects i created on the process? or i have to manually unload models i created? Is it Allowed to Make loading of Resources Global to a controller? - El Forum - 07-15-2007 [eluser]Derek Allard[/eluser] No need to unload anything - resource allocation is handled pretty well. Oh yeah, and welcome to CodeIgniter! Is it Allowed to Make loading of Resources Global to a controller? - El Forum - 07-15-2007 [eluser]n00bPhpCoder[/eluser] Wow I am really Impress with it you can see here what ive done using code igniter. Still exploring tons of possiblities using CI http://121.97.156.37 Is it Allowed to Make loading of Resources Global to a controller? - El Forum - 07-17-2007 [eluser]marcoss[/eluser] [quote author="n00bPhpCoder" date="1184569242"]instead of loading them via functions can we do this? Any Ideas?[/quote] If you mean loading the Model in the controller constructor, that's perfectly fine, i use it like this. Code: <?php |