Codeigniter - I can not print select values in view

1

Well, I'm trying to make a page that shows the user's data that is logged in.

Model:

function getAllDisplayable3()
 {
     $username = $this->session->userdata('username');
     $this->db->select('id_login, nome, username, password, cod_postal, telefone, email, localidade, rua');
     $this->db->from('login');
     $this->db->where('username', $username);
     $result = $this->db->get();
     //echo $username; echo die();
 }

I made the echo of $ username and printed.

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

And gives error: Undefined variable: profile. What do I have to put in order to print the values?

Thank you.

    
asked by anonymous 07.06.2016 / 12:53

1 answer

2

Your data needs to pass through the controller first and then be passed to view.

Model

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

Controller

class Formulario extends CI_Controller {

    public function index()
    {
        $this->load->model('perfil'); // Nome do model

        // Faz a chamada da função
        $dados = $this->perfil->getAllDisplayable3(); 

        // Envia os dados recebidos para a view
        $this->load->view('formulario', $dados);
    }
}

View

<input class="form-control" id="nome" value="<?php echo $perfil; ?>" type="text">
    
07.06.2016 / 13:04