![]() |
Better way to handle data passed to views? - 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: Better way to handle data passed to views? (/showthread.php?tid=7417) |
Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]bcorcoran[/eluser] OK, I've been wondering this for a while but haven't asked. Is there a better way to handle sending data to the view than the following: Code: <?php My question is that I have to duplicate loading the config item for every function, and it's always going to be the same for each one of the functions in this particular controller (it's for static pages -- eschewing the db for now). Is there a better way where I don't have to replicate this every time? I'm already loading my config file with autoload, and then I'm loading the site_config array from it. Another note: I have to include this config array in *every* controller function which contains a view... I don't really know of a better way to do it. Thanks for reading! Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]xwero[/eluser] in your view you can use Code: <?php echo $this->config->item('site_config'); ?> Code: class Site extends Controller { Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]bcorcoran[/eluser] Ah, very nice, thanks. I'm still pretty intermediate at PHP so I am not familiar with certain concepts. Also, you missed one thing in your modified example: Code: $this->load->view('site/home', $data); Code: $this->load->view('site/home', $this->data); Otherwise, it works great. Thanks! Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]xwero[/eluser] you're on your way to become an advanced phper ![]() Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]wolfman2000[/eluser] Personally, I prefer having a separate Library handle the views. Here's my Paste. Feel free to use/modify this. I doubt most of you guys will be using "Pump Pro Edits" as the main title, or using the profiler, etc. It's what I'm currently using on my development server. Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]bcorcoran[/eluser] [quote author="wolfman2000" date="1207684690"]Personally, I prefer having a separate Library handle the views. Here's my Paste. Feel free to use/modify this. I doubt most of you guys will be using "Pump Pro Edits" as the main title, or using the profiler, etc. It's what I'm currently using on my development server.[/quote] Would you care to show an example of how you use this? (i.e. sample controller/view snippets) Better way to handle data passed to views? - El Forum - 04-08-2008 [eluser]wolfman2000[/eluser] I'm not at my development computer right now, but I am using what may be a non traditional approach. Each unique page has their own controller: one controller for news updates, one for credits, one for specific content, etc. Inside the index() function (or one of the other sub functions), I call my library with the page I want to load. The library then takes care of the rest. If I want to supply additional/extra data, I do so in the controller before passing $data. I can explain more later upon request. |