I'm trying to write my own MY_Model base class but I'm facing a weird problem:
/core/MY_Model.php
function __construct() {
if ( !empty($this->table)) {
// query db, etc.
}
else {
// even though that I set $this->table value
// in the child class, I always ended up here
// it's always empty!!!!
log_message('error', 'some error message');
}
// ...
}
}
/models/test_model.php
function __construct() {
parent::__construct();
}
// ...
}
even though that I set $this->table value in the child class, I always ended up finding $table value empty in MY_Model class, it's always empty!!!! any hint please?!
Unless you need something specific/special - you should just use Jamie Rumbelows "MY_Model" - it will probably be better than anything you could write (or me) - and allows you to focus writing other code. No need to re-invent the wheel.
You can get the code from GitHub here
And here is an awesome tutorial that shows you how to use the MY_Model in your application.
Honestly - give it a go - you wont regret it.
In your model constructor, do this:
class Test_model extends MY_Model{
public function __construct()
{
parent::__construct();
$this->table = 'test_model';
}
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With