404 Page Not Found codeigniter url

19,865

Solution 1

codeigniter works on base_url~/index.php/class_nm/function/segment3. Now in your case change file name Cart.php.

localhost/ci/index.php/cart/index

and make sure your function index is public, I guess it will fix your problem :)

Solution 2

You are getting the 404 page not found error because controller "shopcart" is not defined. Instead you have defined a controler "cart". So you should try localhost/ci/index.php/cart instead.

Solution 3

Try adding the url helper as well. That works for me!

Share:
19,865
Admin
Author by

Admin

Updated on June 07, 2022

Comments

  • Admin
    Admin almost 2 years

    I am a beginner using codeigniter. I am using following url "http://localhost/ci/index.php/shopcart" to access the controller and I am getting error 404 page not found

    Controller Code

         <?php
    
        class Cart extends CI_Controller { // Our Cart class extends the Controller class
    
            function Cart()
            {
                parent::CI_Controller(); // We define the the Controller class is the parent. 
    
            }
    
    
        }
    
            function index()
            {
                $this->load->model('cart_model'); // Load our cart model for our entire class 
                $data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products
                $data['content'] = 'cart/products'; // Select our view file that will display our products
                $this->load->view('index', $data); // Display the page with the above defined content
            }
    ?>
    

    Model Code

    <?php 
    
    class Cart_model extends Model { // Our Cart_model class extends the Model class
    // Function to retrieve an array with all product information
        function retrieve_products(){
            $query = $this->db->get('products'); // Select the table products
            return $query->result_array(); // Return the results in a array.
        }  
    
    }
    

    Route

    $route['default_controller'] = "shopcart";
    

    autoload

    $autoload['libraries'] = array('cart' , 'database');
    $autoload['helper'] = array('form');
    
  • Admin
    Admin about 9 years
    localhost/ci/index.php/cart/index is also showing 404 Page Not Found my index function is public by default as mentioned in the attached code with this question. And Please note that my controller file is shopcart.php
  • Ian Patel
    Ian Patel about 9 years
    change it to Cart.php