jamierumbelow / codeigniter-base-model

⛔️DEPRECATED CodeIgniter base CRUD model to remove repetition and increase productivity
MIT License
1.05k stars 478 forks source link

MVC architecture not working #112

Open tonyjdev opened 11 years ago

tonyjdev commented 11 years ago

I have a MVC architecture, directories are like this:

So, in the "module_one/models/one_model.php":

class one_model extends MY_Model
{
    public $primary_key = 'one_id';
    public $belongs_to = array('two' => array(
            'model' => 'two_model',
            '_table' => 'two',
            'primary_key' => 'two_id'
        )
    );
}

show this error: Unable to locate the model you have specified: two_model

If I change the line:

    'model' => 'two_model',

by

     'model' => 'module_two/two_model',

get this error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Admin::$module_two/two_model
Filename: core/Model.php
Line Number: 51

¿How can I fix this and load the model on MVC architecture?

Thanks :)

FDiskas commented 10 years ago

This is HMVC not MVC :)

FDiskas commented 10 years ago

I tested and its worked for me.

// modules/language_module/models/language_model.php
class Language_model extends MY_Model
{
    protected $_table = 'language';
    protected $primary_key = 'language_id';

    public $belongs_to = array(
        'user' => array(
            'model' => 'demo_module/user_model',
            'primary_key' => 'language_id'
        )
    );

    public function languages( )
    {
        return $this->with('user')->get_all();
    }
}
// modules/demo_module/models/user_model.php
class User_model extends MY_Model
{
    protected $primary_key = 'id';

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
}

And in some controller I colling this like so:

$this->load->model( 'language_module/language_model' );
$aData['languages'] = $this->language_model->languages();

$this->load->view( 'language_module/menu_view', $aData );

p.s. I used Modified HMVC CodeIgniter for real HMVC and file and directories structure is the same as yours.