消息:尝试获取非对象的属性.代码点火器错误代码


Message: Trying to get property of non-object. CODEIGNITER ERROR CODE

这是我的控制器:

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

有人可以帮助我确定问题吗?

朋友,这样做。在您的视图页面中,您正在获得$result数组。

<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>

当你可以尝试在模型上代替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>