I 'm writing a custom component and I already get done the router.php:
defined('_JEXEC') or die;
function empresaBuildRoute(&$query) //Esta función divide la url y se trae las variables.
{
$segments = array();
if (isset($query['view']))
{
$segments[] = $query['view'];
unset($query['view']);
}
if (isset($query['padre']))
{
$segments[] = $query['padre'];
unset($query['padre']);
};
if (isset($query['id']))
{
$segments[] = $query['id'];
unset($query['id']);
};
if (isset($query['categoria']))
{
$segments[] = $query['categoria'];
unset($query['categoria']);
};
if (isset($query['empresa']))
{
$segments[] = $query['empresa'];
unset($query['empresa']);
};
return $segments;
}
function empresaParseRoute($segments) //Esta función reconoce las variables y las reacomoda.
{
//print_r($segments); //Si deseas verificar el contenido de la Array "segments".
$vars = array();
switch($segments[0])
{
case 'actividad': //Verifica las View y según cada una del componente, ordena las variables.
$vars['view'] = 'actividad';
$id = explode(':', $segments[2]); //Los segmentos son una array que contiene otra array
$vars['id'] = (int) $id[0]; //La posicion 0 de la array contenida en la posicion 2 de la array anterior
break;
case 'empresa':
$vars['view'] = 'empresa';
print_r($segments);
$categoria = explode(':', $segments[1]);
$vars['categoria'] = (int) $categoria[0];
$empresa = explode(':', $segments[2]);
$vars['empresa'] = (int) $empresa[0];
break;
}
return $vars;
}
It does its job but the url looks like
/actividad/10-hosteleria-y-restaurantes/11-cervecerias
I read a lot but there's just information for remove ID in articles (that's old, joomla 3.x do this by default), nothing about this. Can some one help me with this?
id
into$segments
array. So$segments[] = $query['id'];
should be removed from yourbuild()
function. Also you need to find theid
from thealias
by writing some db queries inside yourparse()
function. eg:$vars['id'] = get_id_from_alias($alias)
where$alias
is a member of$segments
array say$segments[0]
that is defined inside yourbuild()
function.