CodeIgniter load multiple model in same controller [closed] CodeIgniter load multiple model in same controller [closed] codeigniter codeigniter

CodeIgniter load multiple model in same controller [closed]


Try this

class Dashboard extends CI_Controller { function __construct() {      parent::__construct();     $this->load->model("admin/post_model","post_model");    $this->load->model("admin/comment_model","comment_model");  }public function index(){    $data['post_res'] = $this->post_model->getPost();    $data['com_res']  = $this->comment_model->getComments();}


Check if the model correctly extends the CI_Model for comment_model and post_model

example:

  class comment_model extends CI_Model{       }  class post_model extends CI_Model{       }


getComments() is comment_model, not post_model..

You can name your models by passing a second parameter;

$this->load->model('admin/comment_model', 'comments');$data['com_res'] = $this->comments->getComments();