I have installed CodeIgniter_2.1.3 and running in
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.php
The corresponding controller for this page is found at: application/controllers/welcome.php
If 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.
If you are calling like this http://localhost/CodeIgniter_2.1.3/
, then you have to remove default controller from your routes.php
. It should be empty. By default it is set up with welcome controller.
$route['default_controller'] = "" // Replace with your default controller;
routes.php will be inside config folder .
go to application/config/routes.php
$route['default_controller'] = "pages";
Hope this helps you Then go to
/CodeIgniter_2.1.3/index.php/pages/view
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.