I made a website that contains products with the url: http://somesite.com/controller/function/brand_id/product_id. I would want to change those ID’s to more search friendly names. All those ID are in the DB with a name. Is it possible to get those names out of the DB and put them in the URL? This because i can’t use the routing tool. The products and brands are dynamically and could be deleted or (name) changed at any time. So can’t hardcode this into the routes.
Thanks for the effort
You should be able to accomplish this by setting up some wildcard routes for
brand_idandproduct_id. When you are performing the query for the product, you can just check to see if the URI segments are integers (IDs) or strings (names) and query the DB accordingly. I would store a URL-friendly version of the product name (replace spaces and special chars) and then query that, and also use that for generating links throughout the app.Update: Here is a code sample for the logic you would want in the method that you are routing everything through:
and here is an example of the route you would need: