I'm making a custom component in Joomla! 3. Let's call it TestCom (com_testcom).
What I want is to add to items view a simple searching and filtering engines. For this I've created additional, raw view which is responsible for grabbing data from database. Default, html view is sending ajax call to this page during url index.php?option=com_testcom&view=items&format=raw
.
Raw view is grabbing the data and sending back to HTML view.
Almost everything is ok, besides one thing. Problem is the url to see details of the item. Normally I'm using
JRoute::_('index.php?option=com_testcom&view=item&id='.$item->id, false, 2)
which will display http://localhost/mypage/test/item/test-item.html
In raw view it works, but in html view, when ajax is displaying data it looks like this: http://localhost/mypage/componen/testcom/item/test-item.html
which is not working properly.
What I did is changed a little bit pure url to this:
//get menu item
$app = JFactory::getApplication();
$menu = $app->getMenu();
//get component's name
$comName = JRequest::getVar('option');
//get actual view's name
$viewName = $this->_name;
//get menu's item id for our compoent
$menuItem = $menu->getItems( 'link', 'index.php?option='.$comName .'&view='.$viewName, true );
echo JRoute::_('index.php?Itemid='.$menuItem->id.'&view=item&id=1',true,2); ?>');
and this will display in both option (raw and html) the same link:
http://localhost/mypage/test/test-item.html
JRequest
in Joomla 3.x, as it's deprecated. You need to use JInput