I am creating a custom component that will get data by json from another url. So far it works good but I am having some difficult trying to apply a SEF URL with a router.php file.
Example, current url from my component is this: index.php?option=com_mycomponent&id=333
The desired SEF URL (It will not be generated by Jroute, it just need to be read by joomla) is: website.com/alias-id
I only need the id to parse JSON. Alias is irrelevant.
The thing is... I cannot make the router.php work at all. My route never returns the values from my $vars array. It always says: Notice: Undefined variable: vars in [...]router.php on line 30.
I trying everything, but even if I try to put a exact var inside the ParseRoute function. (Like $vars[] = 30; ) the $vars output is still undefined.
I tried countless examples, I even tried using Jumi router.php as a example because I know that is a extension that will recognise the alias on frontend URL without any link on Jroute or menu id... but no luck.
Here is my current router.php. Because there is no query at all (and I have no idea where it comes from btw) I dindt used a $query var on BuildRoute function.
function myComponentBuildRoute()
{
$url = JURI::getInstance();
$myid = end(explode('-', $url)); // gets the id from a /alias-id format
$segments = array();
$segments[] = $myid;
return $segments;
}
function myComponentParseRoute($segments)
{
$vars = array();
$vars['jid'] = $segments[0];
return $vars;
}
print_r($vars);
So maybe I am missing the logic on the router.php at all. Maybe it needs something from view. I am not even sure how I may use the $vars array after it finnaly pass. But then what I need to do to make a SEF url that Joomla will understand and will not give me a 404?