Reputation: 2228
I have two views ie, views/pages/home.php
and views/pages/search_result.php
. I have a controller to load this views ie, controllers/Pages.php
. And also i have one more folder inside view ie, views/templates/header.php
and views/templates/footer.php
When i am pointing the browser to http://localhost/codeigniter/home
everything working perfect.
But the problem is when i am pointing the browser to http://localhost/codeigniter/search_result
, the view footer.php
is also showing. Actually am not given anything inside search_result.php
My controller code is,
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function home($page = 'home')
{
//code to show home.php (http://localhost/codeigniter/home)
if (!file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
else
{
$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);
}
}
public function search_result($page = 'search_result') {
//code to show search_result.php (http://localhost/codeigniter/search_result)
}
}
Inside search_result
function i didn't given any code and while am pointing to http://localhost/codeigniter/search_result
the footer from function home
is showing ie, $this->load->view('templates/footer', $data);
What am doing wrong. Is there any solution to solve this issue. I am beginner in codeigniter.
Upvotes: 0
Views: 1018
Reputation: 38672
Just simply try this
public function home()
{
//code to show home.php (http://localhost/codeigniter/home)
if (!file_exists(APPPATH.'/views/pages/home.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
else
{
$this->load->view('templates/header', $data);
$this->load->view('pages/Home', $data); # changed
$this->load->view('templates/footer', $data);
}
}
Upvotes: 1