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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?