Welcome Guest, Not a member yet? Register   Sign In
Proper method for includes/requires and init script??

OOP Beginner
Hi, I'm pretty new to OOP in general, let alone MVC/CodeIgniter, but the concept seems fantastic!

Personally, I've been making website procedurally like so:



/* ====================================
*        INIT
* ==================================== */
define("SITE_TITLE", "Afferent");
$buildNum = 1;

$page_title = "";

/* ====================================
*        INCLUDES
* ==================================== */


Is there a good tutorial out there for people like me who modularize their website like so? I understand I can make each include a 'view', but to call them over and over again in every controller doesn't seem efficient.

I could also make one template that holds my header, footer, menu, etc. but then what about my content? Each page surely will be different and not carry all the same code...

Init Scripts
If I have code in my 'home' controller that I want to be called for every single page (as it carries a redirect), where would I put it?

Redirect Externally
I had to create a helper at ./system/application/helpers/url_custom_helper.php containing:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

function redirectExternal($uri = '') {
            header("Location: $uri");


just to redirect externally. Is there an external redirect function that I missed or was this necessary?

Thanks so much for your time!

This is no doubt one of the most frequent questions that turns up in the forum; do some hunting around on 'partial views' -- esp. in the FAQ -- and you'll find what you're looking for. Off the top of my head, check out:

Partial views 1


Partial Views 2

Also see URL helpers in the UG for redirects:



I know this is an old thread, but in case anyone is reading, I want to add a link that really helped me:


Theme © iAndrew 2016 - Forum software by © MyBB