I’m trying to set up a website using MVC, but I’m stuck at the very beginning.
In project0/application/controllers I have a pages.php file which looks like:
<?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 in project0/application/views/pages two files named home.php and about.php, containing a “Hello world”.
When I want to visit http://project0/index.php/pages/view/about, it gives me the 404 error: it seems the home.php or about.php files are not existing.
Can somebody help me out?
In your script, try a
getcwd();and then double check the results from that (your current working directory) against the relative path'application/views/pages/'.$page.'.php'. I would guess that you’re not looking for your page in the directory you think you are.