I have installed CodeIgniter_2.1.3 and running in
- Windows 7
- Wamp Server 2.1
- PHP 5.3.5
- Apache 2.2.17
I followed this Codeignitor Static Pages Tutorial link provided in Codeignitor.
I created, file at application/controllers/pages.php with the following code.
<?php class Pages extends CI_Controller
{
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->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
?>
and then I created the header at application/views/templates/header.php with code as below:
<html>
<head>
<title><?php echo $title ?> - CodeIgniter 2 Tutorial</title>
</head>
<body>
<h1>CodeIgniter 2 Tutorial</h1>
and then i created a footer at application/views/templates/footer.php with the following code:
<strong>© 2011</strong>
</body>
</html>
and then when i called http://localhost/CodeIgniter_2.1.3/index.php/pages/view/home
I got this as output
Welcome to CodeIgniter!
The page you are looking at is being generated dynamically by
CodeIgniter.If you would like to edit this page you'll find it located at:
application/views/welcome_message.phpThe corresponding controller for this page is found at:
application/controllers/welcome.phpIf you are exploring CodeIgniter for the very first time, you should
start by reading the User Guide.
instead of getting the home.php with appended header.php and footer.php.
I suspect this is because of some wrong settings in either in codeignitor config or in php config or apache server config.
Best Answer
If you are calling like this
http://localhost/CodeIgniter_2.1.3/
, then you have to remove default controller from yourroutes.php
. It should be empty. By default it is set up with welcome controller.routes.php will be inside config folder.