drr25281 2016-07-28 21:36
浏览 40
已采纳

在CodeIgniter中的项目中遇到php错误

I want to set up my first project in CodeIgniter which includes a database. I've made the proper configurations for database like shown in this tutorial: Everything You Need to Get Started With CodeIgniter.

I have created my database in phpMyadmin. When try to access the project in my localhost this is the error: enter image description here After changing password from 'root' to ' ' now the error is this:

Fatal error: Class 'Model' not found in C:\xampp\htdocs\ci\application\models\diploma_model.php on line 2

This is my model cpde:

<?php
class diploma_model extends Model {
 
    function diploma_model()
    {
        // Call the Model constructor
        parent::Model();
    }
     
    function getData()

        {
            //Query the data table for every record and row
            $query = $this->db->get('data');
             
            if ($query->num_rows() > 0)
            {
                //show_error('Database is empty!');
            }else{
                return $query->result();
            }
        }
 
}
?>

Im new at codeIgniter. Can someone explain why this error occurs? Thanks!

</div>
  • 写回答

2条回答 默认 最新

  • dongtiaozhou4914 2016-07-28 22:21
    关注

    Your tutorial that you have read is very out of date. The current codeigniter website is here

    It would be worth reading through here

    This is the correct way for CI model and anatomy-of-a-model I think because you just extend Model and no CI_Model

    And your construct is wrong to.

    On autoload.php I would autoload database.

    $autoload['libraries'] = array('database');
    

    Filename Diploma_model.php

    <?php    
    
    class Diploma_model extends CI_Model {
    
    public function __construct() {
    
        // Call the Model constructor
        parent::__construct();
    }
    
    function getData() {
      $query = $this->db->get('data');
    
      // This > means greater. So will return results if any found!
    
      if ($query->num_rows() > 0) {
    
         return $query->result();
    
         //return $query->result_array();
    
       } else {
    
           return false;
    
        }
      }
    
    }
    

    Loading of the model

    <?php 
    
    class Example extends CI_Controller {
    
       public function __construct() {
          parent::__construct();
          $this->load->model('diploma_model');
       }
    
       public function index() {
          $data['lists'] = $this->diploma_model->getData();
    
          $this->load->view('someview', $data);
       }
    
    }
    

    The CI User guide for models

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

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题