【问题标题】:404 Page Not Found codeigniter url404页面未找到codeigniter url
【发布时间】:2015-05-19 16:36:56
【问题描述】:

我是使用 codeigniter 的初学者。我正在使用以下 url "http://localhost/ci/index.php/shopcart" 来访问控制器,我收到错误 404 page not found

控制器代码

     <?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');

【问题讨论】:

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


【解决方案1】:

codeigniter 适用于 base_url~/index.php/class_nm/function/segment3。现在在你的情况下更改文件名Cart.php

localhost/ci/index.php/cart/index

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

【讨论】:

  • localhost/ci/index.php/cart/index 也显示 404 Page Not Found 我的索引函数默认情况下是公共的,如本问题所附代码中所述。请注意,我的控制器文件是 shopcart.php
  • 把它改成 Cart.php
【解决方案2】:

您收到 404 页面未找到错误,因为未定义控制器“购物车”。相反,您已经定义了一个控制器“购物车”。所以你应该试试localhost/ci/index.php/cart

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      相关资源
      最近更新 更多