Common model in Codeigniter with HMVC

544 Views Asked by At

i've been use codeigniter with hmvc pattern.my folder structure is something like below enter image description here

Now question is how can i use adminw model in common codeigniter model ?

i've common controller which is as follow

<?php

class MY_Controller extends CI_Controller {

    public function __construct(){
        parent::__construct();
        //here i am checking url if adminw than load model inside adminw folder
        $path = $this->uri->segment(1);
        if($path != ADMIN_FOLDER){
            $this->load->model('modules/SettingModel');<-- BUT THIS IS NOT WORKING
        }else{
            $this->load->model('SettingModel');
        }
        

in short how can i load model that is stored in hmvc folder

1

There are 1 best solutions below

5
Rakesh Hiray On

If your model in..

modules > admin > models > mdl_admin.php

then you can use it in any module's controllers as like..

function __construct()
{
    parent::__construct();
    $this->load->model('admin/mdl_admin','controllers_relevant_module_name');
    ....
    ....
} 

admin - Its module name,

mdl_admin - model name (admin->models->mdl_admin.php),

controllers_relevant_module_name - controller relevant module

Its just for reference.. you may modify as per your code flow requirements