質問

I have been looking at symfony CMF but I cannot figure if it is able to handle my problem.

I want to build a shop bundle where it is possible per language to configure the url to a specific product i.e. /product/{productId}/[productName] for EN and /[productName]-{productId}.html for DK - both leading to the same product. ([productName] just means that content could be here, the id is the real parameter)

My issue is that I cannot figure if it is possible to add such routes to the default dynamic router or if I have to implement RouteProviderInterface on my own, and how I make {{ path(???) }} generate the urls based on the selected language and a product entity as input.

役に立ちましたか?

解決

You have several options:

  • You can use the DynamicRouter with PHPCR or ORM routes that point to your products. There can be as many routes per documents as you want. They can be named anything, so to enforce your naming pattern you would need some coding. If your products can provide the routes that refer to them, the DynamicRouter can even generate the URL directly from the product. The drawback is that you will need to store a database entry per product.
  • You can write your own RouteProvider that generates the route objects from your products. The RouteProviderInterface has only a few methods, and i would hope it should be easy to implement in your case.
  • Did you look into Sylius? https://github.com/Sylius/Sylius/pull/255 tries to add the cmf routing component to sylius. Maybe you can work off that, or at least use it as inspiration.
  • You could also implement your own RouterInterface and use the ChainRouter to hook it into the routing process, but that is probably overkill.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top