Estoy aprendiendo a utilizar codeigniter 3.1.3, siguiendo un tutorial en vídeos; me he encontrado con el siguiente inconveniente:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Test::$db
Filename: core/Model.php
Line Number: 77
Backtrace:
File: /home/claudio/www/ci_cms/application/models/Test_model.php Line: 28 Function: __get
File: /home/claudio/www/ci_cms/application/controllers/Test.php Line: 28 Function: registro
File: /home/claudio/www/ci_cms/index.php Line: 315 Function: require_once
An uncaught Exception was encountered
Type: Error
Message: Call to a member function get() on null
Filename: /home/claudio/www/ci_cms/application/models/Test_model.php
Line Number: 28
Backtrace:
File: /home/claudio/www/ci_cms/application/controllers/Test.php Line: 28 Function: registro
File: /home/claudio/www/ci_cms/index.php Line: 315 Function: require_once
Controlador Test.php
class Test extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
echo 'Index Test...';
}
public function metodo2($var1, $var2) {
//$this->load->database();
//echo '<pre>';
//print_r($this->db->select(['id', 'direccion'])->get('test')- >result_array());
//return;
$this->load->model('test_model', 't_model');
//echo '<pre>';
print_r($this->t_model->registro());
$this->load->view('test/test', ['titulo' => 'Titulo de Test']);
}
}
Modelo Test_model.php
class Test_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function registro($select = null, $where = null, $fetch = null) {
if (is_array($select)) {
$this->db->select($select);
}
if (is_array($where)) {
$this->db->where($where);
}
if ($fetch == 'object') {
$this->db->get('test')->result();
}
$this->db->get('test')->result_array();
}
}
config/database.php
con los datos de conexión? Al igual te falta leer dicha libreria$this->load->library('database');
esto lo realizas en el model o en el arachivoconfig/autoload.php