Codeigniter - select and print values

1

Well, I'm trying to print values on a page of a select I've done in a model. But give me the error: Undefined variable: login. Controller:

function perfil()
{
    $this->load->model('perfil_model');
    $data['list'] = $this->perfil_model->getAllDisplayable3();
    $data['username'] = $this->session->userdata('username');
    $this->load->view('perfil_view',$data);
}   

Model: profile_model

function getAllDisplayable3()
 {
    $this->db->select('id_login, nome, username, password, cod_postal, telefone, email, localidade, rua');
    $result = $this->db->get('login');      
    return $result->result();
 }

View: profile_view

 <input class="form-control" id="nome" value="<?php echo $login->nome?>" type="text">

What is wrong or missing? Thank you.

    
asked by anonymous 06.06.2016 / 23:53

1 answer

0

Within method perfil() you have set $data['list'] and in your View called $login , then change method perfil() to

$data['listPerfil'] = $this->perfil_model->getAllDisplayable3();

Full Code:

function perfil()
{
    $this->load->model('perfil_model');
    $data['listPerfil'] = $this->perfil_model->getAllDisplayable3();
    $data['username'] = $this->session->userdata('username');
    $this->load->view('perfil_view',$data);
} 

Method:

function perfil()
{
    $this->load->model('perfil_model');
    $data['listPerfil'] = $this->perfil_model->getAllDisplayable3();
    $data['username'] = $this->session->userdata('username');
    $this->load->view('perfil_view',$data);
} 

View

<?php foreach($listPerfil as $p): ?>
<input class="form-control" id="nome" value="<?php echo $p->nome;?>" type="text">
<?php endforeach; ?>

Just remembering that the command result (of method getAllDisplayable3() ) returns a list of objects strong>.

Reference Result Arrays

    
07.06.2016 / 01:26