2013-05-06 45 views
0

確定我得到了我的自定義組件的路由器,但我仍然需要它裏面的價值觀和我不知道如何我可以在組件檢索的Joomla元件值router.php

在URL

使用這些值,例如

的index.php?選擇= com_maodeobras &視圖= maodeobras &貓= mymaincat &子= mysubcat

我想期望的結果(我的路由器實現)

個maodeobras/mymaincat/mysubcat.html

的問題是:

我怎麼可以檢索組件或URL變量貓子?

,這裏是我的路由器

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

    if(isset($query['view'])): 
     $segments[] = $query['view']; 
     unset($query['view']); 
    endif; 

    if(isset($query['id'])): 
     $segments[] = $query['id']; 
     unset($query['id']); 
    endif; 

    if(isset($query['cat'])): 
     $segments[] = $query['cat']; 
     unset($query['cat']); 
    endif; 

    if(isset($query['sub'])): 
     $segments[] = $query['sub']; 
     unset($query['sub']); 
    endif; 

    return $segments; 
} 

function MaodeobrasParseRoute($segments) 
{ 
    $vars = array(); 

    $app =& JFactory::getApplication(); 
    $menu =& $app->getMenu(); 
    $item =& $menu->getActive(); 
    // Count segments 
    $count = count($segments); 
    //Handle View and Identifier 
    switch($segments[0]) 
    { 
     case 'maodeobras': 
      //if ($count == 1) { 
       $id = explode(':', $segments[$count-1]); 
       $vars['id'] = (int) $id[0]; 
       $vars['view'] = 'maodeobras'; 
      //} 
      break; 

     case 'categoriasdemãodeobras': 
      $id = explode(':', $segments[$count-1]); 
      $vars['id'] = (int) $id[0]; 
      $vars['view'] = 'categoriasdemãodeobras'; 
      break; 
     case 'madeobrasfiltros': 
      $id = explode(':', $segments[$count-1]); 
      $vars['id'] = (int) $id[0]; 
      $vars['view'] = 'madeobrasfiltros'; 
      break; 

     case 'subcategorias': 
      $id = explode(':', $segments[$count-1]); 
      $vars['id'] = (int) $id[0]; 
      $vars['view'] = 'subcategorias'; 
      break; 
    } 

    return $vars; 
} 

回答

2

我懂了工作,忘記所有的組件製造商作罷垃圾桶,和繼承人創建自己的router.php

的解決方案! 爲查詢:

的index.php選項= com_maodeobras &貓= mymaincat &子= mysubcat &的itemid = 123

ü就要有一個SEF URL像 /mymaincat/mysubcat.html

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

    if(isset($query['cat'])): 
     $segments[] = $query['cat']; 
     unset($query['cat']); 
    endif; 

    if(isset($query['sub'])): 
     $segments[] = $query['sub']; 
     unset($query['sub']); 
    endif; 

    return $segments; 
} 

function MaodeobrasParseRoute($segments) 
{ 
$vars = array(); 

    $vars['cat'] = $segments[0]; 
    $vars['sub'] = $segments[1]; 

    return $vars; 
} 

爲了在您的視圖文件中檢索這些值,請執行以下操作: echo JRequest :: getVar('cat'); 或 echo JRequest :: getVar('sub');

這就是所有!