Welcome Guest, Not a member yet? Register   Sign In
Set Up Template System With Code Igniter
#1

[eluser]Unknown[/eluser]
I'm very new to CF and MVC in general, but I have been writing php for about a year.

I was working through a NetTutsPlus tutorial on how to setup a template system and I already hit some road blocks that I have no idea how to solve. I want to use a template because I want to be as efficient as possible. If it helps, here is a link to the tutorial I worked from http://www.youtube.com/watch?v=gvGymDhY49E

1. I don't know how to change the URL structure.
Currently the template system forces me to go to index.php/site/blog for example.

2. I don't know how to pass in dynamic data to my header and footer using this system.

3. What does extends do? Example: "class Site extends CI_Controller"

Here is my current setup...

views/template.php

Code:
<?php

$this->load->view('/includes/header');

$this->load->view($main_content);

$this->load->view('/includes/footer');

?>

controllers/site.php

Code:
<?php

class Site extends CI_Controller{

function header()
{
  $this->load->library('common');
  $page_names = $this->common->pages();
  
  $page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4);
  
  $title = (array_key_exists($page, $page_names) !== false) ? $page_names[$page]: '';
  
  if (array_key_exists($page, $page_names) !== false)
  {
   $title .= " | Jason Biondo";
  }
  
  $data['header_content'] = $title;
  $this->load->view('template', $data);
}

function about_us()
{
  $data['main_content'] = 'about_us';
  $this->load->view('template', $data);
}

function blog()
{
  $data['main_content'] = 'blog';
  $this->load->view('template', $data);
}
}

?>

views/includes/header.php

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html lang="en" dir="ltr"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html;charset=utf-8" /&gt;
&lt;meta http-equiv="content-script-type" content="text/javascript" /&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="container">





Theme © iAndrew 2016 - Forum software by © MyBB