Sorry, I'm learning the framework.
How can I show data from a related table.
Model
Code:
public function get_product()
{
return $this->table->get()->getResultArray();
}
Controller
Code:
class Product extends Controller
{
protected $ProductModel;
protected $request;
public function __construct() {
$this->ProductModel = new ProductModel();
$this->request = \Config\Services::request();
}
public function index()
{
$data['product'] = $this->ProductModel->get_product();
return view('product/index', $data);
}
}
View
Code:
<tbody>
<?php
foreach($product as $key => $data) { ?>
<tr>
<td><?php echo $key+1; ?></td>
<td><?php echo $data['category_id']; ?></td>
<td><?php echo $data['product_name']; ?></td>
<td><?php echo $data['product_description']; ?></td>
<td>
<div class="btn-group">
<a href="<?php echo base_url('product/edit/'.$data['id']); ?>" class="btn btn-primary btn-sm"><i class="fas fa-edit"></i></a>
<a href="<?php echo base_url('product/delete/'.$data['id']); ?>" class="btn btn-danger btn-sm" onclick="return confirm('Apakah Anda yakin ingin menghapus produk <?php echo $data['product_name']; ?> ini?')"><i class="fas fa-trash-alt"></i></a>
</div>
</td>
</tr>
<?php } ?>
</tbody>
How can I show the name of the category and not the id, Thanks.