【发布时间】: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');
【问题讨论】:
-
localhost/ci/index.php/shopcart 是问题所在,因为它正在搜索 index.php 文件夹。试试localhost/ci/shopcart
-
你的班级名字好像是Cart,所以你可以试试localhost/ci/index.php/cart或localhost/ci/cart
-
localhost/ci/shopcart 显示“在此服务器上找不到请求的 URL /ci/shopcart”。 localhost/ci/index.php/cart 也显示 404 页面未找到。我正在使用 codeigniter 3
-
这不是 CI3 的好代码。这是 CI v 中使用的代码
标签: php codeigniter http-status-code-404