I'm trying to display the data coming from my database in View. I followed the various tutorials I found on the internet but none of them could answer me: /.
Model
public function get_titles() {
$title = $this->db->get('TB_TITLES');
return $title->result_array();
}
Controller
public function titulosCadastrados($page = 'titulosCadastrados') {
if (!file_exists(APPPATH.'views/pages/titulos/'.$page.'.php')) {
show_404();
}
$data['titles'] = $this->title_model->get_titles();
$this->load->view('templates/system-header');
$this->load->view('pages/titulos/titulosCadastrados', $data);
$this->load->view('templates/system-footer');
}
View
<tbody>
<tr>
<?php foreach ($titles as $title) { ?>
<tr><?php echo $title->name ?></tr>
<?php } ?>
</tr>
</tbody>
Table in the database
CREATE TABLE IF NOT EXISTS tb_titles(
ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(100) NOT NULL,
DESCRIPTION VARCHAR(500),
VALUE DOUBLE NOT NULL,
PAID_OUT_AT TIMESTAMP NOT NULL,
REGISTERED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
UPDATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
The displayed error is:
Message: Trying to get property of non-object
Filename: Titles / TitlesCadastrados.php
Line Number: 39
Backtrace:
File: C: \ CibraProgramas \ Xampp \ htdocs \ financas \ application \ views \ pages \ titles \ titulosCadastrados.php Line: 39 Function: _error_handler
Any idea what it might be?