Jamie
Jamie

Reputation: 433

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

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.

Upvotes: 2

Views: 9806

Answers (4)

Wind Mee
Wind Mee

Reputation: 25

In the static page tutorial you are asked to:

Create a file at application/controllers/pages.php with the following code.

But this won't work since the file name needs to start with a capital like this:

application/controllers/Pages.php

This did the trick for me

Upvotes: 1

Chad Hedgcock
Chad Hedgcock

Reputation: 11775

Whether the format is mysite.com/index.php/home or mysite.com/home doesn't matter because it's looking for the view, not the controller.

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

should be

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

That isn't what's causing your problem, though. You're showing a 404 when it evaluates to true, which means that the file actually does not exist. If the file existed, you would get a 404 page.

Check thoroughly and make sure you have the file 'application/views/pages/home.php'.

Upvotes: 0

rgin
rgin

Reputation: 2311

Try changing this line:

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

to this:

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

Upvotes: 3

TigerTiger
TigerTiger

Reputation: 10806

can you change this line with

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

something like

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

and let me know if that works.

Upvotes: 1

Related Questions