• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My_Template class

Hello, i'm trying to create my own tpl class wich allow me to load different tpl's views...
But my OOP experience is very poor Sad I'm getting errors and don't know what to do.

This is my code
  // application/project/libraries/My_Template.php
  class My_Template extends CI_Loader
    public static $template;

    function My_Template()

    function set_template($template=null){
      if ($template == null){
      /* TODO later
        if (session){
          self::$template = $session->item('template');
        } else {
        self::$template = $this->config->item('template');
      } else {
        self::$template = $template;

    function load_view($view, $data=array(), $master=0){
      if ($master){
        return $this->load->view(self::$template.'/', $data);
      } else {
        return $this->load->view(self::$template.'/templates/'.$view, $data);


This class was loaded by ci, from autoload array,.... :/ Could some one help to make this class working? :-S

[eluser]Pascal Kriete[/eluser]
Why are you extending the Loader?

I think you need to take a step back and think about what you want to do. Could you tell us how you want it to work (once it's done) - I'm sure someone will have some pointers. Also, have you read about creating libraries?


If interested in using my idea.. my 'template' system works like struts tiles (j2ee programming - if not familiar)

I have a simple layout file [siteLayout.php]




Then from my controllers I 'inject' my content

$data = array(
               'title' => 'My Page',
               'content' => 'home',
               'breadcrumbs'=>< breadCrumbInfomation >


As you can see I load siteLayout, then inject the contents of home.php into it below the header and above the footer.

This is a real simple way to do templating and works well for me. I hope it does the same for you


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.