• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to CodeIgniter


I am new to codeigniter, I am following code igniter tutorial:

Static Pages

Where should I add this codes:

public function view($page = 'home')

if ( ! file_exists('application/views/pages/'.$page.'.php'))
// Whoops, we don't have a page for that!

$data['title'] = ucfirst($page); // Capitalize the first letter

$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);


I don't really understand the instruction.

In controller.

in which file?

Probably welcome.php, did you change default controller?


ok, I just add them to welcome.php

Now I am trying to view:


I suppose to see the about page, yet I do not. I suppose to see the header and footer. I only see a blank page.

Load one view like your index, then load header and footer in the index, does that make sense?

Have you created the views in your views folder?

Blank page says no view available!

Comment out the views and simply echo something to check it loads ok


you mean creating views.php in views folder?

I have pages folder in views folder which consist of: about and home
I also have templates folder in views folder which consist of: footer and header

Can Recommend a book for you to work through "Wrox" "Professional Codeigniter", it will walk you through all the issues you have, seriously I think you need a good book!

Okay, I just get the ebook. There is too much information in it.

I am trying to get a hold of the basic from the CodeIgniter Tutorial / User Guide. Maybe it's faster.

ok starting with your view files.

in folder: application/views

create the two folders: templates, and pages

in templates folder create or put the view files: header.php, footer.php

in pages folder put: home.php (as an example)

in application/controllers

create a file names: pages.php

in this file put the following code:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pages extends CI_Controller {

function __construct()

public function index()

public function view($page = ‘home’)

  if ( ! file_exists(‘application/views/pages/’.$page.’.php’))
   // Whoops, we don’t have a page for that!

  $data[‘title’] = ucfirst($page); // Capitalize the first letter

/* End of file pages.php */
/* Location: ./application/controllers/pages.php */

that should do the trick

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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