Best practice to code "includes" (views)? |
[eluser]vadimyer[/eluser]
Hello! I'm rather new to CI and first and maybe only question I have right now is how can I make some "general" template file or files (like header.php, footer.php, sidebar.php in WordPress) and then include them just pasting one line of code in every view? Do I have to create views like header_view.php etc. etc. for that? Or is there any other possible method? Thanks in advance for you reply! Also I want to say that I'm looking for the best practice, not the easiest one.
[eluser]marcogmonteiro[/eluser]
Normally i do this: template_view.php with this code: Code: $this->load->view('includes/header_view'); then when i load the view on my controller I do something like this: Code: $data['main_content'] = 'articles_view'; I don't know if this is the best way, but this is how I manage to segment my views.
[eluser]cideveloper[/eluser]
or you could use a template library from these 2 fine gents Colin Williams Phil Sturgeon I have used the first one a lot and it suits most of my needs. I haven't fully tried our Phils but it looks real good too.
[eluser]marcogmonteiro[/eluser]
ok, that's probably would be the way to go then! ![]()
[eluser]vadimyer[/eluser]
Thanks guys! But I like the way you do it, cancerman. Probably, because it's much easier than diving into those template libraries, although they're pretty easy to learn. Maybe any other solutions, people?
[eluser]Narkboy[/eluser]
I tend to do something similar: base.php (tempalte view file): Code: [...] The $content file is set in the controller, and varies from page to page. This way, the view 'frame' is set on the base.php, and area-specific content is set out in the head.php view, nav.php view etc. Save me from having to remember / check that each version is consistent. Typically, for each new design I'll write out 2-3 'bible' view files, a form.php file that contains all possible form related elements, a table.php file, a 'text.php file, etc - that way I can quickly check how to do a given series of elements. Whatever works for you! /B
[eluser]marcogmonteiro[/eluser]
That's good, i normally add one more to all my applications. The error view. This one is always activated with flasdata (normally i only use flashdata for confirm or error messages)
[eluser]Narkboy[/eluser]
[quote author="cancerman" date="1308238468"]That's good, i normally add one more to all my applications. The error view. This one is always activated with flasdata (normally i only use flashdata for confirm or error messages)[/quote] I tend to hold errors in a seperate controller. It feels more secure to me, though makes very little practical difference. Basically, if you hit an actual error that prevents completion, redirect to my-domain.com/error/[error_type]. /B |
Welcome Guest, Not a member yet? Register Sign In |