1

コードの何が問題なのかわかりません.......モデルのロード中にエラーが発生しました.......助けてください........私のコントローラー

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Exams extends CI_Controller {
    public function index(){
        $ob = new exam_class();
        $ob->set_exam(0,'Html exam','1','20');
        $ob->create_exam();
        echo 'success';
    }
}

class exam_class{
    private $id;
    private $title;
    private $catagory;
    private $timeLength;

    function set_exam($id,$title,$catagory,$timeLength){
        $this->id = $id;
        $this->title = $title;
        $this->catagory = $catagory;
        $this->timeLength = $timeLength;
    }

    function create_exam(){
        $this->load->model('examModel');
        $this->examModel->create_exams($title,$catagory,$timeLength);
    }
}

モデル

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ExamModel extends CI_Model {
    public function create_exams($title,$catagory,$timeLength){
        $data = array(
           'title' => $title ,
           'catagory' => $catagory ,
           'timeLength' => $timeLength
        );

        $this->db->insert('exams', $data);
    }
}

error PHP エラーが発生しました

重大度: 通知

メッセージ: 未定義のプロパティ: Exam_class::$load

ファイル名: controllers/exams.php

ライン番号: 26

致命的なエラー: 26 行目の C:\xampp\htdocs\exam\application\controllers\exams.php の非オブジェクトに対するメンバー関数 model() の呼び出し

4

3 に答える 3

2

1 つのファイルに複数のクラスを配置しないでください。コントローラーはこのようなものでなければなりません。

class Exams extends CI_Controller {

    private $id;
    private $title;
    private $catagory;
    private $timeLength;
    public function __construct()
    {
        parent::__construct();
        $this->load->model('examModel');
    }

    public function index(){
        $this->set_exam(0,'Html exam','1','20');
        $this->create_exam();
        echo 'success';
    }   

    function set_exam($id,$title,$catagory,$timeLength){
        $this->id = $id;
        $this->title = $title;
        $this->catagory = $catagory;
        $this->timeLength = $timeLength;
    }

    function create_exam(){
        $this->examModel->create_exams($title,$catagory,$timeLength);
    }
}
于 2013-06-10T08:48:26.620 に答える