So, you want to make sure that you understand the routes, to make sure everything displays the first segment of your URL, since you really only need one controller. This is located in the application / config folder in a file named routes.php
You need to configure it as follows:
$route['(:any)'] = "home/$1"; $route['default_controller'] = "home";
Thus, that matches any (in any of them) in the first segment and directs it to the house / $ 1 (controller / function) ... and then, if there is nothing in the first segment, it matches it to the house / (index function that implied). Take a look at the documentation for the route file so you can understand what you can do with it (you can run regular expressions, advanced routing, etc.), which is really important to know.
So in your home.php controller (controller / home.php or whatever you want to call) you can just have functions matching your url of your url
What is mentioned in other messages about the extension of the base controller, in this case is really not required. But it’s good to have a function that views the load for you so you don’t need to repeat $this->load->view(header) and $this->load->view(footer) , etc. for each function.
What I like to do is create an include folder with my header, footer, nav, etc., create a function that does just that ... with private access:
private function viewloader($view, $data) { $this->load->view('includes/header', $data); $this->load->view('includes/nav', $data); $this->load->view($view, $data); $this->load->view('includes/footer', $data); }
... or using the codeigniter built-in underscore before a function that makes it inaccessible via URL
function _viewloader($view, $data) { $this->load->view('includes/header', $data); $this->load->view($view, $data); $this->load->view('includes/footer', $data); }
Then your functions for each page will look something like this:
function about() { $this->viewloader('about', $data); } function contact() { $this->viewloader('contact', $data); }
So now, as you can see, the viewloader function now loads the views of the header, nav, any kind of $ view and then the footer at the same time ... pretty nice.
You can also remember that you can load any views that you need in the view files themselves (nested views), they do not always need to be downloaded from the controller, although it’s good to keep them so that you don’t need to edit individual view files if you want make significant changes.
Here's what it might look like at the end:
<?php if (! defined('BASEPATH')) exit('No direct script access'); class home extends CI_Controller { //php 5 constructor function __construct() { parent::__construct(); } function index() { $data['title'] = "Welcome To Our Site" $this->viewloader('home', $data); } function contact() { $data['title'] = "Contact Us" $this->viewloader('contact', $data); } function about() { $data['title'] = "About Us" $this->viewloader('about', $data); } private function viewloader($view, $data) { $this->load->view('includes/header', $data); $this->load->view('includes/nav', $data); $this->load->view($view, $data); $this->load->view('includes/footer', $data); } }