![]() |
Global View - 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: Global View (/showthread.php?tid=14465) |
Global View - El Forum - 01-03-2009 [eluser]jaswinder_rana[/eluser] I have header and footer that I use in my views like views/Sample.php Code: <?php echo $this->load->view('header');?> I have sidebars both in header and footer. I want to include some items that I want to be displayed on ALL pages like "5 New listings" on left side and "Featured Listings" on right side. I am not sure how to load those? I can create specific views like new.php and featured.php and then just load those. My problem is, I am not sure how to load data for those views? - Should I create a MY_Controller and then load that data in there? - Should I create a library, put loader function in constructor and then autoload that library? Thanks Global View - El Forum - 01-03-2009 [eluser]Colin Williams[/eluser] You could create a class (library) that handles the template parts (see my sig for one option) or extending the Controller class is always viable. For any app I've done that reaches a certain size and scope, extending the base controller for all requests is typically a must. No reason to avoid it. Global View - El Forum - 01-03-2009 [eluser]jaswinder_rana[/eluser] [quote author="Colin Williams" date="1231036162"]You could create a class (library) that handles the template parts (see my sig for one option) or extending the Controller class is always viable. For any app I've done that reaches a certain size and scope, extending the base controller for all requests is typically a must. No reason to avoid it.[/quote] Thanks. Even if I use your approach, I'd still have to load that data somewhere. And calling that function in every controller doesn't seem sensible to specially if I want to change that content later. So, from library and controller option, which one would you go with? Which is more manageable later on? Global View - El Forum - 01-03-2009 [eluser]Colin Williams[/eluser] The phrases "global" or "in each controller" in CI-speak is nearly always synonymous with "MY_Controller" ![]() Global View - El Forum - 01-03-2009 [eluser]jaswinder_rana[/eluser] That was quick. Thanks Colin. MY_Controller it is. Global View - El Forum - 01-04-2009 [eluser]jaswinder_rana[/eluser] I did add it but it din't work. I then searched in the forum and found that I need to change my controllers and change "extends Conntroller" to "extends MY_Controller" (I am calling it MY_Controller). Is there a way around this? I am hoping not to do this as I have so many files. And if later on I want to change it then it'd be pain. Lets say that I do change my views and load the data, but how can I pass it globally so that any view can access it? I am sending data to my views via $data array and then pass to it when I load that view ($this->load->view('view',$data) ![]() Thanks Global View - El Forum - 01-04-2009 [eluser]jaswinder_rana[/eluser] I found $this->load->vars() function and it's working (in MY_Controller contructor). Is there another better way to do it? |