Reputation: 1537
I'm executing the following query in the get_distribuidor() function of my model:
public function get_distribuidor()
{
$this->load->helper('url');
$query = $this->db->query("SELECT * FROM distribuidor where id_distribuidor='1';");
foreach ($query->result_array() as $row)
{
echo $row['id_distribuidor'];
echo $row['nome_empresa'];
echo $row['cod_postal'];
echo $row['localidade'];
echo $row['telefone'];
echo $row['fax'];
echo $row['email'];
}
$res = array(
'nome_empresa' => $row['nome_empresa'],
'morada' => $row['morada'],
'cod_postal' => $row['cod_postal'],
'localidade' => $row['localidade'],
'telefone' => $row['telefone'],
'fax' => $row['fax'],
'email' => $row['email']
);
return $res;
}
Now, returning $res to the controller, i don't know very well how to separate the multiple fields the array result contains.
I'm using this on a function of the controller:
$data['nome_produto']=$this->fichas_model->set_fichas();
$teste=$this->fichas_model->get_distribuidor();
$this->load->view('produtos/ponto1',$data, $teste);
to write on the view something like this:
<input type="input" name="morada" value="<?php echo $teste['morada'];?>" /><br />
but it's not working, can someone point me what am I doing wrong?
Upvotes: 3
Views: 12702
Reputation: 15045
$teste=$this->fichas_model->get_distribuidor();
$this->load->view('produtos/ponto1',$data, $teste);
should be:
$data['teste'] = $this->fichas_model->get_distribuidor();
$this->load->view('produtos/ponto1',$data);
The 3rd parameter for view()
is used if you want to grab the content of view()
into a variable. To pass data to the view you need to add it as an array item of $data
.
For Example:
$data = array(
'title' => 'My Title',
'heading' => 'My Heading',
'message' => 'My Message'
);
$this->load->view('blogview', $data);
// You then access $title, $heading, $message in the view file
What you are doing with above edit is the following essentially:
$data = array(
'teste' => $this->fichas_model->get_distribuidor()
);
$this->load->view('produtos/ponto1', $data);
// You then access $teste in the view file,
// which will be an array so you can access $teste['morada']
Upvotes: 6