1

I'm facing one weird problem with my Codeigniter project.

I have two model files in the following paths:

models/public/Dish_model.php
models/admin/Dish_model.php

For front-end and back-end models respectively.

In the controller which is in the following path:

controllers/admin/Dish.php

I'm trying to load the admin area model file using:

$this->load->model('admin/dish_model');

But it is loading the public model file.

Even if I comment this line out the public model file still gets loaded.

This all happened suddenly it was working fine before and I haven't changed any of the mentioned files recently.

Any help?

3
  • 1
    How you know it is loading another model file? use alternative way. $this->load->model('admin/dish_model', 'amodel'); and use like this$this->amodel->method(); Commented Feb 4, 2017 at 17:20
  • I know because I tried calling a function from each one and only the one from the other model worked! Commented Feb 4, 2017 at 17:31
  • I've also tried your suggestion ... no difference :\ Commented Feb 4, 2017 at 17:31

2 Answers 2

2

In case anyone else encounter the same issue.

In my case and after carefully following the execution path of the controller I found that the other model was being loaded by a library in the autoload list.

Removing that library from the autoload array fixed the problem.

Sign up to request clarification or add additional context in comments.

Comments

2

to call/load a model from its subdirectory or subfolder.

models/public/Dish_model.php

let's say in Dish_model

class Dish_model extends CI_Model{
    public function __construct(){
       parent::__construct();
    }
    public function the_method(){
       return 'return value';
    }
}

models it's a native ci model directory and public it's a subdirectory. so to load the Dish_model do this on controller

$this->load->model('public/Dish_model','DModel');

the DModel it is like an alias. so to call the model from the controller is

echo $this->DModel->the_method();

and it will return return value hope its help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.