I just learned about routing in CodeIgniter and now I am lil bit confuse.
I have an URL like this : http://localhost/norwin/list_group/get_product_by_group/1
Which is:
list_group is controller,
get_product_by_group is method,
and '1' is passing parameter.
I want to minimize the URL with route. So I can have an URL like :
http://localhost/norwin/group/'group_name'
And this is my code on route.php :
$route['group/(:any)'] = 'list_group/get_product_by_group/$1';
this is my controller :
public function get_product_by_group($group_name)
{
if($this->uri->segment(3))
{
$this->load->database();
$data['product_data'] = $this->group_model->list_product_by_group($group_name);
$this->load->view('fend/list_product', $data);
}
else
{
redirect('list_group');
}
}
And this is my code on view which call the controller :
<?= base_url('group/'. $value->group_name);?>
my problem is : I can not get any result of the route, it always send me to 'list_group'.
Maybe someone here have a good approach to do this.
Thanks for your help.
$this->uri->segment(3)in your URL. You only have two segments 'group' and 'group_name'. change it to$this->uri->segment(2)- Kamran