0

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

4
  • Just a side note, please don't use JRequest in Joomla 3.x, as it's deprecated. You need to use JInput
    – Lodder
    Oct 13, 2015 at 10:52
  • As for your actual post, what's the issue? You've posted what appears to be a solution
    – Lodder
    Oct 13, 2015 at 10:55
  • It is solution, I want to share this with others. Maybe it will be useful for someone in future.
    – TheNut
    Oct 13, 2015 at 11:10
  • 1
    In which case, please post the solution as an actual answer below, in the "answer" section ;)
    – Lodder
    Oct 13, 2015 at 11:11

1 Answer 1

3

The final source code is:

// Get menu item
$app = JFactory::getApplication();
$menu = $app->getMenu();

// Get component's name
$comName = JFactory::getApplication()->input->get('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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.