kohana 3.2电子商务路由example.com/categoryname/productname/

时间:2022-10-13 13:42:46

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

我正在kohana 3.2上开展电子商务。我需要设置路由,以便能够使用这样的链接:

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...

example.com/categoryname/ - 显示给定类别的所有产品。在那里有像example.com/categoryname/1,example.com/categoryname/2等那样的分页会很高兴...

second:

第二:

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

example.com/categoryname/productname - 显示所选产品。

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).

categoryname和productname当然是字母数字。类别列表是动态的,所以我不能制作与类别一样多的控制器。我想省略index.php中的hacks和主要的bootstrap更改,以便能够轻松地将代码迁移到ko3.3和upper(如果有的话)。

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

我正在阅读有关lambda回调函数的内容,也许这就是解决方案。

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

无论如何,如果这是不可能的,也许可以路由:example.com/shop/categoryname/productname,example.com/shop/categoryname/1。

thanks for any help. dev1

谢谢你的帮助。 DEV1

1 个解决方案

#1


0  

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.

希望这可以帮助。

#1


0  

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.

希望这可以帮助。