0
I am learning Codeigniter and trying to pass an array to the View through my controller and when I call this array in the view is presented to me as undefined.
This is my controller:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Consulta extends CI_Controller {
public function index() {
$this->load->view("index");
}
public function listar_consultas() {
$this->load->view("listar");
}
public function salvar_consulta() {
$this->load->model("model_marcar_consulta");
if ($this->model_marcar_consulta->salvar_dados()) {
$this->load->view("sucesso");
} else {
$this->load->view("erro");
}
}
public function listando_consultas() {
$this->load->model("model_marcar_consulta");
$consulta = $this->model_marcar_consulta->retorna_lista_consulta();
$variaveis["consulta"] = $consulta;
$this->load->view("listar", $variaveis);
}
}
?>
And this is my View:
<table border="1">
<tr>
<td>Id</td>
<td>Especialidade</td>
<td>Data de Marcação</td>
<td>Horario de Marcação</td>
<td>Observação</td>
<td>Data de públicação</td>
</tr>
<?php foreach($consulta -> result() as $linha): ?>
<tr>
<td><?php echo $linha->id ?></td>
</tr>
<?php endforeach; ?>
</table>
I really don’t understand this mistake:
PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: views/listar.php
Line Number: 21
Fatal error: Call to a Member Function result() on a non-object in C: Program Files (x86) Easyphp-5.3.8.0 www marcar_query application views listar.php on line 21
You have already checked the return of the method
$this->model_marcar_consulta->retorna_lista_consulta()
?– gabrielhof
Hey, valdiney, check it out editions of the question to see how to format a post here in the stack :)
– brasofilo
If you post the code of your model it would be easier to help you. For without knowing what is encoded there we have to guide ourselves by deductions.
– Jklaus