How to handle views more simply ? |
[eluser]sikko[/eluser]
Hi everyone, I'm looking for a way to handle views more simply. Instead of including for each view, a header and a footer (in the view file): Code: <?php load_view('header_view') ?> Code: CONTENT STUFF I've found this blog post dealing with this issue: http://www.devshed.com/c/a/PHP/Handling-...Igniter/3/ The only problem now, is that I have to load these views, not in the view file, but in the controller class. Code: function index(){ Don't you know how could I make it less "intrusive" ? Maybe could we put the header and footer stuff in a parent view class that would be loaded in every view ? Thank you for your help.
[eluser]vitoco[/eluser]
A simplle way it's to set a CONSTANT and use HOOKS, not the way i do it...but it's an idea 1.- in the function set a variable to "tell" the hook that you wanna add header an footer Code: function index() 2.- use "display_override" hook USER GUIDE : HOOKS Code: $CI =& get_instance();
[eluser]sikko[/eluser]
Thanks for your Good idea, I'll try. I didn't know hooks and it's a good feature. And how do YOU do it ?
[eluser]vitoco[/eluser]
calling views from views..old fashion way, but i'm used to
[eluser]sikko[/eluser]
Hey I got a question, Code: // echo 'header' view
[eluser]davidbehler[/eluser]
From the User Guide: Quote:There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. That being said, these are interchangable: Code: echo $CI->load->view('header_view',array('header'=>'Header Section') , true ); Code: $CI->load->view('header_view',array('header'=>'Header Section')); You can use this to assign the data to a variable like this: Code: $string = $CI->load->view('header_view',array('header'=>'Header Section') , true );
|
Welcome Guest, Not a member yet? Register Sign In |