Question

I'm working on my ecommerce on kohana 3.2. i need to setup the routing to be able to use links like this:

first:

example.com/categoryname/ - this shows all products of given category. it would be nice to have pagination there like example.com/categoryname/1, example.com/categoryname/2 etc...

second:

example.com/categoryname/productname - this shows the chosen product.

categoryname and productname are alphanumeric of course. the categories list is dynamic, so i cannot make as many controllers as categories. i would like to omit hacks in index.php and major bootstrap changes, to be able to migrate the code easily to ko3.3 and upper (if ever out).

i'm reading about lambda callbacks functions, and maybe this is the solution.

anyway, if this is not possible, perhaps routing for : example.com/shop/categoryname/productname, example.com/shop/categoryname/1 is possible.

thanks for any help. dev1

Was it helpful?

Solution

It depends on the rest of the routes. If these are the only two routes, then it's quite easy to do:

Route::set('categories', "<category_name>(/<page>)", array('page' => "\d+")
->defaults(array(
    'controller' => "category",
    'page'       => 0   
);

Route::set('product', "<category_name>/<product_name>")
->defaults(
    array(
        'controller' => "product"
    )
);

This is just an example. You can for example route both to the same controller but different actions. It just depends on how you want it.

But this setup doesn't make it easy to add additional routes on the root level.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top