Message: Undefined variable: ver

i'm making a product crud in codeigniter but i have this problem with my code:

A PHP Error was encountered Severity: Notice

Message: Undefined variable: ver

Filename: views/productos_view.php

Line Number: 51

Backtrace:

File: C:\wamp64\www\catalogo\application\views\productos_view.php Line: 51 Function: _error_handler

File: C:\wamp64\www\catalogo\application\controllers\Welcome.php Line: 23 Function: view

File: C:\wamp64\www\catalogo\index.php Line: 315 Function: require_onc

Welcome.php

class Welcome extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see https://codeigniter.com/user_guide/general/urls.html
 */
public function index()
{
    $this->load->view('productos_view');
    }
}

Controller function

//controlador por defecto
public function index(){

    //array asociativo con la llamada al metodo
    //del modelo
    $productos["ver"]=$this->productos_model->ver();

    //cargo la vista y le paso los datos
    $this->load->view("productos_view",$productos);
}

Model

public function ver(){
    // //Hacemos una consulta
    $consulta=$this->db->query("SELECT * FROM catalogo;");
    // Devolvemos el resultado de la consulta
    return $consulta->result();
}

Upvotes: 0

Views: 612

Answers (2)

Hip Hura
Hip Hura

Reputation: 143

see Mr. TimBrownlaw explanation, try add this code on you controller,

public function __construct()
{
    parent::__construct();
    $this->load->model('productos_model');
}

put on top index function

public function index()
{
$ver = ''; //Declare blank variable
$productos = array(); //Declare blank array
$ver = $this->productos_model->ver(); //get from model

$productos["ver"] = $ver; //assigne in $productos array

//cargo la vista y le paso los datos
$this->load->view("productos_view",$productos);
}

and can you show productos_view code?

Upvotes: 0

Alok Mali
Alok Mali

Reputation: 2881

Repalce your code in Welcome controller with the below code.

class Welcome extends CI_Controller {
   public function index() {
        $productos["ver"] = array();
        $this->load->view("productos_view",$productos);
     }
 }

Because you are not sending $ver in your welcome controller.

Upvotes: 0

Related Questions