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

#10
[eluser]Rolly1971[/eluser]
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:

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

class Pages extends CI_Controller {

function __construct()
{
  parent::__construct();    
}

public function index()
{
  $this->view();
}

public function view($page = ‘home’)
{

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

  $data[‘title’] = ucfirst($page); // Capitalize the first letter
  
  $this->load->vars($data);
  $this->load->view(‘templates/header’);
  $this->load->view(‘pages/’.$page);
  $this->load->view(‘templates/footer’);

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

that should do the trick


Messages In This Thread
New to CodeIgniter - by El Forum - 08-23-2012, 01:41 AM
New to CodeIgniter - by El Forum - 08-23-2012, 01:47 AM
New to CodeIgniter - by El Forum - 08-23-2012, 07:22 AM
New to CodeIgniter - by El Forum - 08-23-2012, 07:40 AM
New to CodeIgniter - by El Forum - 08-23-2012, 07:50 AM
New to CodeIgniter - by El Forum - 08-23-2012, 07:52 AM
New to CodeIgniter - by El Forum - 08-23-2012, 08:31 AM
New to CodeIgniter - by El Forum - 08-23-2012, 08:33 AM
New to CodeIgniter - by El Forum - 08-23-2012, 08:58 AM
New to CodeIgniter - by El Forum - 08-23-2012, 10:07 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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