0

I'm a beginner in PHP and CodeIgniter framework, I have found out similar problems and tried to fix the error but it still keeps on telling me

Message: Undefined property: stdClass::$image Filename: controllers/ItemController.php

Line Number: 137

MODEL

class ItemModel extends CI_Model {

    public function itemList () {

    return $this->db->select("items.*, supplier.name as supplier_name")
                    ->from("items")
                    ->join("supplier", "supplier.id = items.supplier_id", "both")
                    ->get()
                    ->result();

    }


    public function deleteItem($id) {
        $id = $this->security->xss_clean($id);
        $this->db->trans_start();
        $this->db->where('item_id', $id)->delete('ordering_level');
        $this->db->where('item_id', $id)->delete('prices');
        $this->db->where('id', $id)->delete('items');

        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            return false;
        }

        return $this->db->trans_commit();

    }

    public function getDetails($id) {
        $id = $this->security->xss_clean($id);
        return $this->db->where('id', $id)->get('items')->row();
    }

    public function item_info($id) {
        $id = $this->security->xss_clean($id);
        $sql = $this->db->where('id', $id)->get('items');
        return $sql->row();

    }

    public function update_item($id,$name,$category,$description,$price_id, $image, $supplier_id) {

       $item = $this->db->where('id',$id)->get('items')->row();

       $data = array(
            'name' => $name,
            'category_id' => $category,
            'description' => $description,
            'supplier_id' => $supplier_id
            );
        $data = $this->security->xss_clean($data);
            if ($image != '')
            $data['image'] = $image;

        return $this->db->where('id',$id)->update('items',$data);
    }

    public function get_all_item() {
        $items = $this->db->select('name')->get('items');
        return $items->result_array();
    }

    public function total() {
        return $this->db->select("SUM(prices.price * ordering_level.quantity) as total")
                    ->from("items")
                    ->join("prices", "prices.item_id = items.id", "both")
                    ->join("ordering_level", "ordering_level.item_id = items.id", "both")
                    ->get()
                    ->row();
    }

}

CONTROLLER

class ItemController extends CI_Controller {



        $datasets = array_map(function($item) {
        $itemPrice = $this->PriceModel->getPrice($item->id);
        $itemCapital = $this->PriceModel->getCapital($item->id);
        $stocksRemaining = $this->OrderingLevelModel->getQuantity($item->id)->quantity ?? 0;
        $itemSupplier = $this->db->where('id', $item->supplier_id)->get('supplier')->row()->name ?? '';

    return [
        $this->disPlayItemImage($item->image), //line 137
                $item->name,
        $this->categories_model->getName($item >category_id),
                '₱' . number_format($itemCapital),
                '₱' . number_format($itemPrice),
                $stocksRemaining . ' pcs',
                $item->name,
                $itemSupplier,
               ];

        }, $items);

        echo json_encode([
            'draw' => $this->input->post('draw'),
            'recordsTotal' => count($datasets),
            'recordsFiltered' => count($datasets),
            'data' => $datasets
        ]);
    }

VIEW

     <div class="panel-heading">
         Items List

     </div>

     <!-- /.panel-heading -->
     <div class="panel-body">
         <table class="table table-responsive table-hover table-bordered" id="item_tbl">
           <thead>
            <tr>
                <th width="8%">&nbsp;</th>
                <th width="20%">Item Name</th>
                <th width="10%">Category</th> 
                <th width="11%">Capital Per/Item</th>
                <th width="11%">Retail Price</th>
                <th width="10%">Stocks</th>
                <th width="10%">Total</th>
                <th width="10%">Supplier</th>
                <th width="10%">Action</th>
            </tr>
        </thead>
        <tbody>


        </tbody>
    </table>
</div>
sticky bit
  • 36,626
  • 12
  • 31
  • 42
11 Yael
  • 9
  • 1
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – miken32 May 23 '19 at 18:19
  • 1
    it means that `$item->image` doesn't exist in the object. either because the row doesn't exist in the returned query, or the query returned no rows. – Alex May 23 '19 at 20:05
  • sorry: because the *column* doesn't exist or the query returned no rows – Alex May 24 '19 at 01:33

0 Answers0