我已經嘗試了與其他職位有關的建議,但沒有喜悅。我試圖在CodeIgniter中創建一個從數據庫中獲取數據的模型,但它說沒有找到類CI_Model。我在主索引文件中的系統路徑設置正確,並且我已經在autoload文件中自動加載了這個模型,我找不出這個問題。我意識到很多功能都是一樣的,我還沒有完成寫它們,我使用第一個作爲佔位符。如何修復CodeIgniter:致命錯誤「Class'CI_Model'not found」
**編輯:我更新了所有這些文件與人的建議,並且仍然收到相同的錯誤。
模型
<?php
class Model_appointments extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function getAppointments()
{
$query = $this->db->get('appointments');
return $query->result();
}
public function getActiveAppointments()
{
$query = $this->db->get('appointments');
return $query->result();
}
public function getCancelledAppointments()
{
$query = $this->db->get('appointments');
return $query->result();
}
public function addAppointments()
{
$this->name = $_POST['name'];
$this->details = $_POST['details'];
$this->date = time();
$this->db->insert('appointments', $this);
}
}
?>
前端控制器
<?php
include 'application/controllers/databaseConnection.php';
include 'application/models/Model_appointments.php';
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Controller_name extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Model_appointments'); #load Model
}
}
class Front_controller {
public function startFrontController() {
$newDatabase = new Mydb('localhost', 'root', '', 'webinnovate');
}
}
$newController = new Front_controller();
echo $newController->startFrontController();
$newAppointments = new Model_appointments();
$newAppointments->getAppointments();
?>
**控制器
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'webinnovate';
class Mydb {
public $query;
public $myConnection;
public function __construct($host, $username, $password, $dbname)
{
//establish connection
$this->myConnection = mysqli_connect($host, $username, $password, $dbname);
}
}
?>
你的控制器的名稱是什麼? – thepiyush13
我有一個名爲databaseConnection.php的控制器和一個frontController,我將爲它們添加代碼。 –
你可以在'config/database.php'中選擇你的數據庫 –