0

i'm developing a new site and i have this situation:

- Products
 \_ Category1
    \_Product1
    \_Product2
 \_ Category2
    \_Produc1
    \_Product2

I have created my Product controller to show all the category but now i need to create a controller for each category, is it possibile? I would have something like:

www.example.com/product/category/product-name

how can i setup my controller? i can't write a method for each category because this is not definited...

1
  • are you using a database to store the category and products? Commented Feb 12, 2012 at 1:50

1 Answer 1

1

You should use the Product Controller, add a function load_category($category_name='') and route URL segment to this function.

Edit app/config/routes.php and add a line like this:

$route['product'] = 'product/index';
$route['product/(:any)'] = 'product/load_category/$1';

An so any URL like: www.example.com/product/categorya or www.example.com/product/categoryb or .. will send a request to load_category methos from Product Controller.

Add this for products:

$route['product/(:any)/(:any)'] = 'product/load_product/$2';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.