1
votes

I have a controller Categories with action index and params(params will contain category name) which makes my url http://localhost/categories/index/(category_name)

I want my url to be written like this http://localhost/(category_name)

But i also have sub categories and more deep level sub categories. So now my url should be written like this http://localhost/(category_name)/(sub_categories) or more deep level http://localhost/(category_name)/(sub_categories)/(sub_sub_categories)

Is there a way to route my url to unlimited params of the action.

The below code is working

$route['(.+)'] = 'categories/index/$1';

but it affects to all the controllers and no other controllers seems to be working

I want to know is there another way to achieve the same.

Thanks!

1
why you need to do like this...? because get method is having some limitations like it accepts around 2000 chars not more than that so you can opt for another way to do so like using post method with having as many fields as you have different category type .. here you can have two fields for main category and sub category and make these field array and store as many items you have in their respective fields - sandeep_kosta
Ok suppose i limit it upto 10 levels and keep it under 1000 chars.. So is it possible to route? - AbuHuraira Lakdawala
yeah it is possible but you know that it is not the efficient solutions as we should keep our url neat and clean so whenever we should encounter with huge volume of data then we should opt for post but its all up to you - sandeep_kosta
Ok great, can you write the code please! - AbuHuraira Lakdawala
I would stick with only one segment as name of category or subcategory. But also, you can make breadcrumbs to follow all subs to the root category. Study hierarchical data in mysql. - Tpojka

1 Answers

0
votes

You can use uri_to_assoc(). Check this page.