【问题标题】:joomla mvc component redirect with friendly urljoomla mvc 组件重定向与友好的 url
【发布时间】:2013-10-08 15:54:01
【问题描述】:

我的控制器中有这样的代码

class MyController extends MyBaseController {

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

}

我还在菜单名称“查看购物车”中创建了一个与我的查看购物车相关联的菜单,每次单击此按钮时,网址为 domainname.com/view-cart,但在 mvc 中使用重定向时,网址为 domainname.com/index.php?option=com_foo&view=cart

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

【问题讨论】:

    标签: php joomla friendly-url


    【解决方案1】:

    您需要在 url 中传递 Itemid 以创建所需的 seo:

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

    您应该关闭 SEO 并查看菜单项中的 Itemid 是什么,然后在您的网址中使用它。

    或者你可以像这样动态地做:

    $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;
    

    【讨论】:

    • 我认为必须有一个动态的方法来做到这一点。我现在正在使用这种方法。但这对我来说似乎不对,因为每次使用此扩展程序时,我都需要手动将 Id 插入代码中。
    • 但是这样我还是需要知道$menuitem。如果我移动我的菜单或删除它并在其他地方创建我仍然需要转到代码以使其 url 友好
    猜你喜欢
    • 2011-10-19
    • 1970-01-01
    • 2019-08-01
    • 2012-11-20
    • 2012-12-07
    • 2014-04-16
    • 2014-02-24
    • 2018-04-28
    • 2012-05-22
    相关资源
    最近更新 更多