这是我的控制者:
public function visualizar(){
$this->data['custom_error'] = '';
$this->load->model('mapos_model');
$this->data['result'] = $this->financeiro_model->verporid($this->uri->segment(3));
$this->data['emitente'] = $this->mapos_model->getEmitente();
$this->data['view'] = 'financeiro/vermovimiento';
$this->load->view('tema/topo', $this->data);
}
这是我的模特:
function verporid($id){
$this->db->select('lancamentos.*, clientes.*');
$this->db->from('lancamentos');
$this->db->join('clientes','clientes.idClientes = lancamentos.clientes_id');
$this->db->where('lancamentos.idLancamentos',$id);
$this->db->limit(1);
return $this->db->get()->row();
}
这是我的观点:
<table class="table">
<tbody>
<tr>
<td style="width: 40%; padding-left: 0">
<ul>
<li>
<span><h5>Cliente</h5>
<span><strong>Nombre: </strong><?php echo $result->nomeCliente?></span><br/>
<span><strong>Dirección: </strong><?php echo $result->rua?>, <?php echo $result->numero?></span><br/>
<span><strong>Ciudad: </strong><?php echo $result->bairro?>, <?php echo $result->cidade?></span><br/>
<span><strong>Email: </strong><?php echo $result->email?></span><br/>
<span><strong>Teléfono: </strong><?php echo $result->telefone?></span><br/>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
我收到此错误:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: financeiro/vermovimiento.php
Line Number: 32
有人可以帮我找出问题吗?
答案 0 :(得分:0)
<table class="table">
<tbody>
<tr>
<td style="width: 40%; padding-left: 0">
<ul>
<li>
<span><h5>Cliente</h5>
<span><strong>Nombre: </strong>
<?php
foreach($result as $data)
{
echo $data->nomeCliente;
}
?></span><br/>
</li>
</ul>
</td>
</tr>
答案 1 :(得分:0)
当你可以尝试而不是模型上的row()是row_array()
function verporid($id){
$this->db->select('lancamentos.*, clientes.*');
$this->db->from('lancamentos');
$this->db->join('clientes','clientes.idClientes = lancamentos.clientes_id');
$this->db->where('lancamentos.idLancamentos', $id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->row_array();
} else {
return FALSE;
}
}
然后在您的控制器上
public function visualizar(){
$this->data['custom_error'] = '';
$this->load->model('mapos_model');
if ($this->uri->segment(3)) {
$some_info_data = $this->financeiro_model->verporid($this->uri->segment(3));
$this->data['nomeCliente'] = $some_info_data['nomeCliente'];
$this->data['rua'] = $some_info_data['rua'];
$this->data['numero'] = $some_info_data['numero'];
$this->data['bairro'] = $some_info_data['bairro'];
$this->data['cidade'] = $some_info_data['cidade'];
$this->data['email'] = $some_info_data['email'];
$this->data['telefone'] = $some_info_data['telefone'];
}
$this->data['view'] = 'financeiro/vermovimiento';
$this->load->view('tema/topo', $this->data);
}
查看
<table class="table">
<tbody>
<tr>
<td style="width: 40%; padding-left: 0">
<ul>
<li>
<span><h5>Cliente</h5>
<span><strong>Nombre: </strong><?php echo $nomeCliente;?></span><br/>
<span><strong>Dirección: </strong><?php echo $rua;?>, <?php echo $numero;?></span><br/>
<span><strong>Ciudad: </strong><?php echo $bairro;?>, <?php echo $cidade;?></span><br/>
<span><strong>Email: </strong><?php echo $email;?></span><br/>
<span><strong>Teléfono: </strong><?php echo $telefone;?></span><br/>
</li>
</ul>
</td>
</tr>
</tbody>
</table>