Default Template For All Views |
[eluser]shreder[/eluser]
Hello. I am creating my first application and i have a question. I want to create a "master" template that will apply to all views. I will be placing header.php & footer.php inside views/template and i want those files to be used in every single view file without calling them each time. What's the best solution for this? Thank you.
[eluser]TheFuzzy0ne[/eluser]
Extend the Controller class, and load it via a helper class which can be loaded in the constructor. The question is, however, are you absolutely certain this is right for you. If you ever start using Ajax in your application, or if you want to send a download without the entire page reloading, it may have repercussions.
[eluser]xwero[/eluser]
i recommend this library but there are others that can be used for your requirement.
[eluser]shreder[/eluser]
Thank you for your help but i'm still finding it confusing. I have a difference controller for each section of my site, how do I create a controller that will contain the template structure for all the other controllers? Thank you.
[eluser]xwero[/eluser]
The easiest solution is to create a library that has a function which contains your template. Code: class Customview Code: class Section extends Controller
[eluser]gtech[/eluser]
create a template library, and then autoload it in config/autoload.php.. I havnt tested it but off the top of my head it might go somthing like: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); [edit]ahh beaten to it[/edit]
[eluser]xwero[/eluser]
gtech why do you use the return as string parameter for the view files? from 1.6 let CI do the heavy work for you
[eluser]gtech[/eluser]
I sometimes like making life difficult for myself, it beats playing chicken with the traffic. Your right no need to return the content if you don't want to, unless you want to do somthing other than display the data (which is probably unlikely) though it still is a good idea to pass the template file as a parameter into the function |
Welcome Guest, Not a member yet? Register Sign In |