404找不到codeigniter网址

时间:2015-03-17 09:48:01

标签: php codeigniter http-status-code-404

我是使用codeigniter的初学者。我正在使用以下网址" http://localhost/ci/index.php/shopcart"访问控制器,我收到错误404页面

控制器代码

     <?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
        }
?>

型号代码

<?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['default_controller'] = "shopcart";

自动加载

$autoload['libraries'] = array('cart' , 'database');
$autoload['helper'] = array('form');

3 个答案:

答案 0 :(得分:3)

codeigniter适用于base_url~ / index.php / class_nm / function / segment3。现在,您需要更改文件名Cart.php

localhost/ci/index.php/cart/index

并确保您的功能indexpublic,我想这会解决您的问题:)

答案 1 :(得分:1)

您收到404页面未找到错误,因为控制器&#34; shopcart&#34;没有定义。相反,你已经定义了一个控制器&#34; cart&#34;。所以你应该试试localhost/ci/index.php/cart

答案 2 :(得分:1)

尝试添加网址助手。这对我行得通!