joomla-路由器在获取产品名称时更改url

joomla-路由器在获取产品名称时更改url,joomla,Joomla,我已经在joomla中构建了自己的组件,客户现在想要一个友好的URL f.e com/someplace/{product id}-{product name}。所以我像这样建造了自己的路由器 function componentBuildRoute(&$query) { $segments = []; if (isset($query['view'])) { $segments[] = "szkolenie"; unset($query['view']); } if

我已经在joomla中构建了自己的组件,客户现在想要一个友好的URL f.e com/someplace/{product id}-{product name}。所以我像这样建造了自己的路由器

function componentBuildRoute(&$query)
{
$segments = [];

if (isset($query['view'])) {
    $segments[] = "szkolenie";
    unset($query['view']);
}

if (isset($query['product_id'])) {
    $productName = JFilterOutput::stringURLSafe(strtolower(getProductName($query['product_id'])));
    $newName = $query['product_id'] . '-' . $productName;
    $segments[] = $newName;

    unset($query['product_id']);
}
return $segments;
}
和解析路由函数

function componentParseRoute($segments)
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$item =& $menu->getActive();
$count = count($segments);

switch ($item->query['view']) {
    case 'catalogue' : {
        $view = 'training';
        $id = $segments[1];
    }
        break;
}

$data = [
    'view' => $view,
    'product_id' => $id
];
return $data;
}
在buildroute函数段结束时,我得到了我想要的东西,在解析路由开始时,我得到了类似的东西
website.com/szkolenie/1-krakow您没有名为“krakow”的产品吗

如果没有,您可以尝试从构建函数中删除$productName,只需检查此“krakow”是自动添加的还是来自getProductName()函数

我还注意到,我猜您在函数getProductName()中有一个错误

应该是

->where('#__component_product.product_id = ' . $productId)
->where('#__s4edu_product.product_id = ' . $productId)
->where('#__component_product.product_id = ' . $productId)