i want show my products name in url now i get my product with id and my url display like that. www.mydomain.com/home/single/1
i want to show my product url with product name Like. www.mydomain.com/home/single/New-Dell-Laptop
Here is my code that's get post with it's id number.
Controller
//get all products
public function index()
{
$data['products'] = $this->front->get_products();
$this->load->view('index',$data);
}
//get single product
public function single($id)
{
$data['product']=$this->front->get_product($id);
$this->load->view('product',$data);
}
Model
//get all products
public function get_products()
{
$this->db->select()
->from('vendor_products')
->where('DESC','date_added');
$data = $this->db->get();
return $data->result_array();
}
//get single product
public function get_product($id)
{
$this->db->select()
->from('vendor_products')
->where('prod_id',$id);
$data = $this->db->get();
return $data->first_row('array');
}
Views
//show all products index.php
<?php foreach($products as $one) : ?>
//create link for single product
<a href="<?=base_url();?>home/single/<?=$one['prod_id'];?>">
<?=$one['product_name'];?>
</a>
<p><?=$one['product_price'];?></p>
//show single product (product.php)
<p><?=$product['product_name'];?></p>
<p><?=$product['product_price'];?></p>
<p><?=$product['product_description'];?></p>