I can not do SELECT

2

Model:

public function exibir_noticia()
{  

  $consulta = $this->db->query('SELECT * FROM Noticia_Site_Cairu');
  return $consulta->result();
}

Controller

public function index()

{
    $this->load->model('noticia_model');
    $consulta = $this->noticia_model->exibir_noticia();         
    //print_r($casdatrado);
    $this->load->view('v_home', $consulta);
}

When I show in the view:

                foreach ($consulta as $exibir):{            
                echo '                  
                <tr class="success">
                    <td>'.$exibir->titulo.'</td>
                    <td>'.$exibir->texto.'</td>
                    <td>'.$exibir->imagem.'</td>
                    <td>'.$exibir->link.'</td>
                    <td>'.$exibir->nome_link.'</td>
                    <td>'.$exibir->video.'</td>
                    <td>'.$exibir->data.'</td>
                </tr>';
                }endforeach;

This error appears:

  

A PHP Error was encountered

     

Severity: Notice

     

Message: Undefined variable: query

     

Filename: views / v_home.php

     

Line Number: 88

     

Backtrace:

     

File: /var/www/html/admnoticias/application/views/v_home.php Line: 88   Function: _error_handler

     

File: /var/www/html/admnoticias/application/controllers/Home.php Line:   17 Function: view

     

File: /var/www/html/admnoticias/index.php Line: 315 Function:   require_once

    
asked by anonymous 13.10.2016 / 17:11

1 answer

2

$consulta does not exist in the view because it has not been defined, see the controller code:

$this->load->view('v_home', $consulta);

To define the name of the variable that will be manipulated in the view, create an associative array:

$this->load->view('v_home', array('consulta' => $consulta));
    
13.10.2016 / 17:14