How to use model in codeigniter controller?
P粉207969787
P粉207969787 2024-01-29 14:21:46
0
1
641

I'm very new to codeigniter-3 framework and I'm using a model in a controller like this $this->load->model('model_name') It's working fine, I'm trying Using the following way but it threw an error, can you help me fix this

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粉207969787
P粉207969787

reply all(1)
P粉976737101

You can have a try

<?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;
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template