Karthi prime Karthi prime - 3 months ago 12
PHP Question

Codeignitor 404 error

I am following the tutorial-Static pages, from codeignitor 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?

Answer

please try following

if (file_exists(APPPATH."views/pages/". $page. ".php")) {

   $this->load->view("pages/". $page);

} 

APPPATH = well self explanatory

Comments