Equivalent of 'include' statement - 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: Equivalent of 'include' statement (/showthread.php?tid=31532) |
Equivalent of 'include' statement - El Forum - 06-23-2010 [eluser]Bionicjoe[/eluser] I have two view files, one for just looking at a ticket and one for editing a ticket. I'm re-using a bunch of the same code in each file. What is the best way to do this so I don't need to layout the same field data in each view file? File 1 (plus there's a bunch more fields set up this way) Code: $ticketnumber = array( File 2 (same fields plus a value attribute) Code: $ticketnumber = array( Creating a file to include and using this didn't work. (loading at beginning of view file) Code: $this->load->file('system/application/include/outageview_inc.php', false); Equivalent of 'include' statement - El Forum - 06-23-2010 [eluser]rbnc[/eluser] Defining arrays should be done at a controller level. I'd create a helper function for making these arrays and call it in the controller and pass it into the views. Equivalent of 'include' statement - El Forum - 06-23-2010 [eluser]Clooner[/eluser] To load a view file inside a view use Code: $this->load->view('viewfile'); Equivalent of 'include' statement - El Forum - 06-23-2010 [eluser]John_Betong[/eluser] [quote author="clooner" date="1277308478"]To load a view file inside a view use Code: $this->load->view('viewfile'); Sometimes I use this quick way inside a view and it works Code: <?php echo include '_view_snippet_to_include.php'; What are the advantages or disadvantages? edit spelling Equivalent of 'include' statement - El Forum - 06-23-2010 [eluser]Clooner[/eluser] [quote author="John_Betong" date="1277317936"] Sometimes I use this quick way inside a view and it works Code: <?php echo include '_view_snippet_to_include.php'; What are the advantages or disadvantages? [/quote] You'll be able to pass parameters to it and it goes through the loader/output procedures of CI which makes you be able to use hooks or overwrite it... Basically it will be more flexible! Equivalent of 'include' statement - El Forum - 06-23-2010 [eluser]John_Betong[/eluser] Quote:Clooner - 23 June 2010 09:45 PM Many thanks - now that has got me thinking |