download12749 2015-03-17 09:48
浏览 58
已采纳

404找不到codeigniter网址

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');
  • 写回答

3条回答 默认 最新

  • doulachan8217 2015-03-17 10:29
    关注

    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 :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?