CodeIgniter - Array to String conversion error

0

I am creating a function to obtain interpreter data based on the interpreter ID. This is the function that I created:

interprete_model.php

Models

public function interpreteID($id)
{
        //consultar los datos
        $this->db->select('*');

        $this->db->where('id_interprete', $id);

        $this->db->from('tbl_interpretes');       

        $query = $this->db->get();

        if($query->num_rows() > 0 )
        {
            return $query->result();
        }
        else
        {
            return false;
        }   


}

I'm calling this method in my interpreter / profile.php file:

Controller

public function index()
{
        $id = $this->session->userdata('user_id');
        echo "User ID ".$id;

        $query = $this->interprete_model->interpreteID($this->session->userdata('user_id'));

        echo "consultar los datos: ".$query;
        //vista
        $this->load->view('perfil_view',$data);
}

When I do this I get an error saying:

missing the data on the web.

Could someone please tell me why he is doing this?

    
asked by Diego Sagredo 05.05.2017 в 15:32
source

1 answer

1

What happens is that you are printing an array like String, in your model you are returning return $query->result(); that returns an array, if you want to print this array you could use print_r ()

Your controller is like this:

public function index()
{
        $id = $this->session->userdata('user_id');
        echo "User ID ".$id;

        $query = $this->interprete_model->interpreteID($this->session->userdata('user_id'));

        echo "consultar los datos: ".$query; // El error esta aquí
        //vista
        $this->load->view('perfil_view',$data);
}

You could do the following:

public function index()
{
        $id = $this->session->userdata('user_id');
        echo "User ID ".$id;

        $query = $this->interprete_model->interpreteID($this->session->userdata('user_id'));

        echo "consultar los datos: "; 
        print_r($query); // Usar print_r() para imprimir el arreglo;
        //vista
        $this->load->view('perfil_view',$data);
}
    
answered by 05.05.2017 / 15:43
source