- users->controllers->Users.php
users->models->Test_model.php - welcome->controllers->Welcome.php
класс Test_model расширяет CI_Model {
Код: Выделить всё
function __construct() {
parent::__construct();
}
public function db_example()
{
return $this->db->get('mir_users')->result();
}
public function test(){
echo 'test model call';
}
и в Welcome.php
Код: Выделить всё
class Welcome extends MX_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/test_model');
}
public function index()
{
//this will give the output
$this->test_model->test();
//thiw will throw error
$this->test_model->db_example();
}
Код: Выделить всё
$this->test_model->test()Код: Выделить всё
Message: Undefined property: Test::$db
Код: Выделить всё
$autoload['libraries'] = array('database');
Версия Codeigniter: 3.1.0
Подробнее здесь: https://stackoverflow.com/questions/390 ... b-in-model
Мобильная версия