繁体   English   中英

404页面未找到codeigniter网址

[英]404 Page Not Found codeigniter url

我是使用Codeigniter的初学者。 我正在使用以下URL“ 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');

codeigniter在base_url〜/ index.php / class_nm / function / segment3上运行。 现在,根据您的情况更改文件名Cart.php

本地主机/ci/index.php/购物车/索引

并确保您的函数indexpublic ,我想它将解决您的问题:)

由于未定义控制器“ shopcart”,因此出现404页面未找到错误。 相反,您已经定义了一个控件“购物车”。 因此,您应该改用localhost/ci/index.php/cart

也尝试添加url帮助器。 这对我行得通!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM