0
votes

I'm completely lost on how to use the routing capabilities of Joomla for a custom component. Here is an example link that is being sent to the custom component through a form submission:

http://superiordash.com/products/dash-kits/index.html?make_id=8&model_id=6&year_id=48&option=com_mmg&view=products&page=list&sel_make_id=-1&sel_model_id=-1&sel_year_id=-1&Itemid=580

What I want to do is grab the make_id, model_id, and year_id, find the corresponding values in the database and use them for the url as such: products/dash-kits/YEAR-MAKE-MODEL.html

So for the example link above:

http://superiordash.com/products/dash-kits/2002-acura-rsx.html

Any ideas from the greats out there?

Also, from what I understand from the documentation - Am I going to have to find a way to explode the rest of the query or it will be attached at the end of url? And if so - is there a way to explode every part of the query except year, make, and model, no matter what it is?

Any help would be most grateful. I've been searching for solutions, half solutions etc. and will continue to do so.

1

1 Answers

0
votes

It's actually quite easy. You will need to use 2 functions in your router.php:

ComponentNameBuildRoute

and

ComponentNameParseRoute

The build route will return an array containing the elements to be displayed in the URL. For example, for a link that is http://www.test.com/products/category-name/product-name, the build route function will return array('category-name', 'product-name'); . The array is passed to a Joomla function automatically to generate the SEF URL.

The parse route function will translate the SEF URL into a GET URL. The function will receive $segments as a parameter, and that segments will consist of the portions in the URL, such as category-name and product-name. In that function, you will need to get the ID of the category and the product, and return an array that is something like array('category_id'=>$category_id, 'product_id'=>$product_id);

You can check the router.php for the banners component (which is the simplest component) and use it as a startup point.