我对 codeigniter-3 框架非常陌生,我在像这样的控制器中使用模型 $this->load->model('model_name')
它工作正常,我正在尝试使用以下方式,但它抛出了一个错误,你能帮我解决这个问题
An uncaught Exception was encountered Type: Error Message: Class 'models\TestModel' not found
TestController.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); use \models\TestModel; class TestController extends CI_Controller { public function student(){ $obj = new TestModel(); $value = $obj->student_college(); echo $value; } }
P粉9767371012024-01-30 00:33:33
你可以尝试一下
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class TestController extends CI_Controller { public function __construct() { parent::__construct(); // Load model $this->load->model('TestModel'); } public function student(){ $obj = new TestModel(); $value = $obj->student_college(); echo $value; } }