Php – CodeIgniter Static Page Tutorial(Unable to load the requested file)

PHP

I've recently downloaded CodeIgniter and install it in XAMPP htdoc -> codeigniter(application,system,user guide,index.php,license.txt)

I've tried to follow with the tutorial posted in CodeIgniter's User Guide on creating static pages but I keep getting this error:

Unable to load the requested file: pages/home.php

The controller is at application/controllers/pages.php with the following code:

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);
    }
}

The tutorial also mentioned about creating header.php in application/views/templates/header.php and footer.php in application/views/templates/footer.php, which are just html code and echo out the page title.

And finally also creating a home.php and about.php in application/views/pages/ directory. For home.php and about.php I only type out some plain text.

Where did I go wrong. Any advice would be greatly appreciated. 🙂 Thank you.

Best Answer

Try changing this line:

if(file_exists('application/views/pages/'.$page.'.php'))

to this:

if(!file_exists( APPPATH . 'views/pages/'.$page.'.php'))
Related Topic