Codeigniter - select and print values

Asked

Viewed 191 times

1

Good, I’m trying to print values on a select page I did on a model. But it gives 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: perfil_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.

1 answer

0


Within the method perfil() you put $data['list'] and in its View calling for $login, then change the method perfil() for

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

Complete 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);
} 

Observing: If it is even to display a list of values it could then be so:

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 also that the command result (of the method getAllDisplayable3()) returns a object list.

Reference: Result Arrays

Browser other questions tagged

You are not signed in. Login or sign up in order to post.