0

I got a code like this in my controller

class MyController extends MyBaseController {

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

}

I also created a menu associated with my view cart in menu name "View Cart" every time i click this button the url is domainname.com/view-cart but when use redirect in mvc the url is domainname.com/index.php?option=com_foo&view=cart

How can i create a redirect in mvc that it work with the front-end link or at least create a user friendly url

Duc Phan
  • 175
  • 1
  • 3
  • 14

1 Answers1

0

You need to pass Itemid in url to create desired seo:

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

You should turn of SEO and look what Itemid is in your menu item a use it in your url.

Or you can do it dynamically like this:

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

Then the $link would look:

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

Or you can take it from whatewer menu item you want like this:

$item = JFactory::getApplication()->getMenu()->getItem( $menuitem );//$menuitem is the id of menu
$itemid = $item->id;
JTC
  • 3,344
  • 3
  • 28
  • 46
  • I thought there must be a dynamic way to do this. I am using this method right now. but it is not seem right to me because every times I use this extension I need to manually insert the Id into the code. – Duc Phan Oct 07 '13 at 01:24
  • But this way i still need to know $menuitem. if i move my menu or delete it and created somewhere else i still need to go to the code to have it url friendly – Duc Phan Oct 09 '13 at 04:30