0

我有这个 url 来显示属性:

index.php?option=com_jea&view=properties&city=2:citta&Itemid=164

sef: sito.it/2-citta.html

此 url 显示属性:

index.php?option=com_jea&view=property&city=2:citta&id=1:trivano&Itemid=164

sef: sito/1-trivano/2-citta.html

但我想

sito.it/2-citta/1-tivano.html

这是路由器:

function JeaBuildRoute(&$query){
$segments = array();

if(isset($query['view'])) {
    unset( $query['view'] );
}

if (isset($query['layout'])) {
    $segments[] = $query['layout'];
    unset( $query['layout'] );
}

if(isset($query['id'])) {
    $segments[] = $query['id'];
    unset( $query['id'] );
};
if(isset($query['city'])) {
    $segments[] = $query['city'];
    unset( $query['city'] );
};

return $segments;

function JeaParseRoute($segments)
{ $vars = array();
   $app =& JFactory::getApplication();
   $menu =& $app->getMenu();
   $item =& $menu->getActive();
   // Count segments
   $count = count( $segments );
   //Handle View and Identifier
   switch( $item->query['view'] )
   {
           case 'properties':
                   if($count == 1) {
                           $vars['view'] = 'properties';
                            $id   = explode( ':', $segments[$count-1] );
                            $vars['city']   = (int) $id[0];
                   }
                   if($count == 2) {
                           $vars['view'] = 'property';
                   }
                   $id = explode( ':', $segments[$count-1] );
                   $vars['id'] = (int) $id[0];
                   break;
           case 'property':
                   $id   = explode( ':', $segments[$count-1] );
                   $vars['id']   = (int) $id[0];
                   $vars['view'] = 'property';
                   break;
   }
   return $vars;}
4

1 回答 1

0

也许您可以尝试颠倒这两个 if 的顺序

   if(isset($query['city'])) {
        $segments[] = $query['city'];
        unset( $query['city'] );
    };

  if(isset($query['id'])) {
        $segments[] = $query['id'];
        unset( $query['id'] );
    };
于 2012-10-25T11:29:43.493 回答