1

mysqlをCodeIgniterに接続しようとしています。このエラーが発生しました:

load->database(); 
$query = $this->db->get('student'); return $query->result(); } } ?>

Fatal error: Class 'Student_model' not found in 
C:\wamp\www\CodeIgniter\system\core\Loader.php on line 303

これが私のコードです:

モデル

class Student_model extends CI_Model
{

    function __Construct()

    {
        parent::__Construct();
    }

    public function student_getall()
    {
        $this->load->database();
        $query = $this->db->get('student');
        return $query->result();
    }
}

見る

foreach($query as $row)
{
    print $row->fname;
    print $row->lname;
    print $row->roll;
    print $row->address;
    print "<br>";
}

コントローラ

class Student extends CI_Controller
{
    function __Construct()
    {
        parent::__Construct();
    }

    public function getall()
    {
        $this->load->model('student_model');
        $data['query'] = $this->student_model->student_getall();
        $this->load->view('student_view',$data);
    }
}
4

4 に答える 4

2

問題は

function __Construct()
{
        parent::__Construct();
}

Cの代わりに首都を見ることができますc

もう一度、 file using で開始し、の後にスペースを入れずに<?phpfile で終了していることを確認してください。?>?>

于 2012-10-01T06:33:41.763 に答える
0
May be your model starts with <?
And in yuour php.ini, shorttages is off thats why the issue is there.
Either enable shorttag or user <?php instead of <?
I found out this solution.
于 2013-03-19T09:03:56.497 に答える
0

これ

function __Construct()
{
    parent::__Construct();
}

小文字の 'c' にする必要があります。student_model.phpモデルフォルダーに正しく保存されているかどうかを確認してください

/Codeigniter/application.models

于 2013-10-11T02:07:38.033 に答える
0

データベース ライブラリは頻繁に使用されるため、自動的にロードすることをお勧めします。application/config/autoload.php ファイルで定義でき、変数は次のとおりです。

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

モデルのファイル名は、

student_model.php

クラス名は

Student_model

and $this->load->model('student_model') = $this->load->model('Student_model');

これは大文字と小文字を区別しません。

`

于 2012-09-29T08:57:03.690 に答える