R
R
Rodion Yurchenko2015-09-15 10:38:47
CodeIgniter
Rodion Yurchenko, 2015-09-15 10:38:47

How to configure ROUTE to pass one OR two parameters?

Good afternoon
, there is a url sitename.com/cat/1/2
where cat - product categories
1 - category number
2 - page (pagination)
in routes I write:
route['cat/(:num)/(:num)'] = " main/cat/$1/$2";
here
in the function
public function cat($id, $page=0)
BUT
if there is no page (1st page) - then the routes redirect to a 404 page ....
that is, it does not find the 2nd parameter because the link looks like sitename.com/ cat/1
how to set up routes correctly (make the 2nd parameter optional) ?
Or is my logic wrong at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Khomenko, 2015-09-15
@aassdds

route['cat/(:num)/(:num)'] = "main/cat/$1/$2";
route['cat/(:num)'] = "main/cat/$1";

Try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question