Search code examples
phpcodeignitercodeigniter-2

Codeigniter 404 error is shown


I am following the tutorial-Static pages, from codeigniter website.

  1. I extracted the codeignitor zip into my local server.
  2. Edited the line

    $config['base_url']='http://localhost/'; 
    

in application /config/config.php

  1. Created the file: application/controllers/pages.php to have following contents:

    <?php
    
    class Pages extends CI_Controller {
    
    public function view($page = 'home')
    {
        if ( ! file_exists('/var/www/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);
    }
    }
    
  2. Created the file: application/views/templates/header.php with some HTML content.

  3. Created the file: application/views/templates/footer.php with some HTML content.

Now, when I go to

  localhost/index.php/pages/view/about

I expect the 'about' page, but 404 error is shown.

Why is that?


Solution

  • please try following

    if (file_exists(APPPATH."views/pages/". $page. ".php")) {
    
       $this->load->view("pages/". $page);
    
    } 
    

    APPPATH = well self explanatory