Joomla MVC 组件使用友好 URL 重定向


joomla mvc component redirect with friendly url

我在控制器中得到了这样的代码

class MyController extends MyBaseController {
 function redirectToCart() {
    $link = JRoute::_('index.php?option=com_foo&view=cart');
    $this->setRedirect($link);
  }
}

我还在菜单名称"View Cart"中创建了一个与我的视图购物车关联的菜单,每次单击此按钮时,网址都会domainname.com/view-cart但是在 mvc 中使用重定向时,网址domainname.com/index.php?option=com_foo&view=cart

如何在 mvc 中创建重定向,使其与前端链接一起使用,或者至少创建一个用户友好的 url

您需要

在 url 中传递Itemid来创建所需的 seo:

$link = JRoute::_('index.php?option=com_foo&view=cart&Itemid=your_itemid');

您应该打开SEO并查看菜单项中的Itemid,并在您的URL中使用它。

或者你可以像这样动态地执行此操作:

$itemid = JRequest::getint( 'Itemid' );

然后$link将看起来:

$link = JRoute::_('index.php?option=com_foo&view=cart&Itemid='.$itemid);

或者你可以像这样从你想要的菜单项中获取它:

$item = JFactory::getApplication()->getMenu()->getItem( $menuitem );//$menuitem is the id of menu
$itemid = $item->id;