codeigniter-base-model
codeigniter-base-model copied to clipboard
MVC architecture not working
I have a MVC architecture, directories are like this:
- codeigniter application folder
- controllers
- config
- ...
- modules (the MVC)
- module_one
- controllers
- models
- one_model.php
- views
- module_two
- controllers
- models
- two_model.php
- views
- module_one
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 :)
This is HMVC not MVC :)
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.