![]() |
How do use includes? - 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 do use includes? (/showthread.php?tid=13026) |
How do use includes? - El Forum - 11-07-2008 [eluser]Nathan Payne[/eluser] Hey, I am new to code igniter and want to know how I use includes. I have started building a web page but don't want to replicate every line of code so includes are the best answer, but how do I use them with code igniter? Thanks How do use includes? - El Forum - 11-07-2008 [eluser]bastones[/eluser] You can call functions from within your controller like $this->functionName(); such as: Code: <?php How do use includes? - El Forum - 11-07-2008 [eluser]Nathan Payne[/eluser] I meant in terms of headers and footers. Thanks though. How do use includes? - El Forum - 11-07-2008 [eluser]bastones[/eluser] Ah. If you want specific functions to point to specific views you use something like this: Code: <?php Remember the array elements become variables, so to get the array contents you use: echo $var; How do use includes? - El Forum - 11-07-2008 [eluser]Aken[/eluser] Yeah, just create views for your header and footer files, then call them in your controllers. How do use includes? - El Forum - 11-08-2008 [eluser]Steve Grant[/eluser] The way I do it is to have all output directed to a single view file, which includes a number of generic "component" files. In the controller, I then pass an array of files which contain the *actual* page content (i.e. stuff that is specific to the particular page you're viewing) and one of the "component" files contains a foreach loop on that file list to recursively include the files in the list. File Structure: Code: views/ Controller (extract): Code: function index() Single view file: Code: <html> Content file: Code: <?php |