Trying to get property of non-object pada Codeigniter

Bantuannya temen" hehe

-Model :

  function cariSaldoCustomer($nama)
    {
        $this->db->distinct();
        $this->db->select("*");
        $this->db->from("kartu");
        $this->db->join("user","user.id_user=kartu.id_user");
        $this->db->where("user.id_user",$nama);
        return $this->db->get()->row();
    }

-Controller

 function saldo(){
        $data['title']="Settings";
        if($this->session->userdata("username") == null)
        {
            redirect("web/index");
        }
        else
        {
           $data['title']=$this->session->userdata("username");
        }
        $data['voucher'] = $this->m_web->getVoucher();
            foreach($data['voucher']->result_array() as $row){
            if($row['tgl_exp'] < date("Y-m-d")){
                $this->m_web->hapusVoucher($row['id']);
            }
        }
        if($this->uri->segment(3)=="delete_success")
            $data['message']="<div class='alert alert-success'>Deleted Successfully!</div>";
        else if($this->uri->segment(3)=="add_success")
            $data['message']="<div class='alert alert-success'>Topup berhasil, tunggu konfirmasi</div>";
        else if($this->uri->segment(3)=="voucher_succes")
            $data['message']="<div class='alert alert-success'>Saldo Anda Berhasil Ditambah</div>";
        else
            $data['message']='';
        $data['web'] = $this->m_web->getDatasaldo($this->session->userdata("id_user"))->result();
        $saldo = $this->m_web->cariSaldoCustomer($this->session->userdata('id_user'));
        $data['saldo'] = $saldo->saldo; // ERROR DISINI
        $this->template->display('web/topup',$data);
    }

-Pesan

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/web.php

Line Number: 641

avatar deni2
@deni2

58 Kontribusi 11 Poin

Diperbarui 6 tahun yang lalu

1 Jawaban:

You should look at this

if you are limiting your results to 1 as in your get_where instruction then return


$q->row_array() // for array

And

 $q->result_array() // for object

And in Controller do this

 $products = $this->products_model->getProductsQuantity($id);
$quantity = $products->quantity; // Object notation

And

 $quantity = $products['quantity']; // Array notation

Jadi codingan yg harus dirubah;

 $saldo = $this->m_web->cariSaldoCustomer($this->session->userdata('id_user'))->result_array();

source: https://stackoverflow.com/questions/13428941/codeigniter-getting-error-on-both-array-notation-and-object-notation

avatar keccikun
@keccikun

364 Kontribusi 196 Poin

Dipost 6 tahun yang lalu

Login untuk ikut Jawaban