我是PHP和CodeIgniter框架的初学者,我发现了类似的问题并试图解决该错误,但它仍然不断告诉我
消息:未定义的属性:stdClass :: $ image 文件名:controllers / ItemController.php
行号:137
模型
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();
}
}
控制器
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
]);
}
查看
<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%"> </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>