The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

19

Here is a technique I used (cannot remember where I found it). $app = JFactory::getApplication(); $menu = $app->getMenu(); $menuItem = $menu->getItems( 'link', 'index.php?option=com_example&view=reporting', true ); echo JRoute::_('index.php?Itemid='.$menuItem->id); This has worked wonders for me.


4

the output from JRoute will depend on what you feed it. JRoute::_("index.php?option=com_content&view=article&id=10"); might return something else than JRoute::_("index.php?option=com_content&view=article&id=10&catid=5"); In fact if you have a menu item category blog listing for catid=5, the latter might give you the menu-url (I ...


3

One thing is, that you're trying to create a router in the old way, it changed over time. Now router is a class. Second thing is, one of your component views have to be set as a front-page for a system. Without that, in most websites the default router will be com_content's router, so every wrong URL(url that don't have a proper menu item/parent item) will ...


3

Here is how I ended up getting it to work: $live_site = substr(JURI::root(), 0, -1); $app = JApplication::getInstance('site'); $router = &$app->getRouter(); $url = $router->build($live_site.'/index.php?option=com_icagenda&view=list&layout=event&id=' . $id . '&Itemid=' . $Itemid); $url= $url->toString(); $eventLink= ...


3

JRoute is not reliable on the backend. Your approach may work on a simple install, but if you have a third-party SEF plugin, or even some slightly unorhodox routing in third-party components, this will fail miserably. So I won't answer how to get rid of the 500 error. But propose an alternative solution. In a popular SEF extension, ACEsef if I remember ...


3

You can use php method http_build_query to generate url encoded query string. Club all the different parameters in an array and pass it to this method. Like $base_url = 'index.php?'; $parameter = array('id'=>'1', 'option'=>'view', 'task'=>'delete'); $base_url .= http_build_query($parameter);


3

I think I see the issue with the search module form destination url. The form action attribute needs the option and view parameters. I see you added them as hidden field at the end of the form, but try removing those fields and adding to the JRoute url like so: <form name="books-search" action="<?php echo JRoute::_('index.php?option=com_usedbooks&...


3

The key here is to set up your components router.php file (which should be found in the root folder of your component on the front end) with logic that will search for and select the appropriate menu item. I would love to see this automatically happen, but as far as I know this isn't the case. It would probably be best to work this block of code in to some ...


2

Afaik JRoute will take the active Itemid (and also the active option) if none is provided. If that doesn't work, it means that the call to your code comes without Itemid to begin with. If so, the easiest thing would be to add the Itemid to the intial call. If you need to look up the menu item, I would not do a direct query but use JMenu instead.


2

You can customize the 404 error (example show a custom page or send somewhere other than the homepage) by adding a PHP file to your template, name it error.php and place it in the root of the template (next to the index.php of the template). Inside that file you can indicate what to do, for example send to somewhere in your site (update /SOMEWHEREINYOURSITE ...


2

This isn't an error but expected behavior. If you navigate to Components > Redirect in the Joomla Administrator's interface, you will see a list of all URLs requests resulting in a 404. Joomla automatically records them in this component and the re-routes the request to the home page. The reason why is two fold, first is to prevent a negative user ...


2

We made this problem go away by updating Joomla to 2.5.24 (a painless point-release upgrade) and updating Document Seller to its 3.5 version, and the problem described above resolved itself exactly as @johanpw suggested.


2

I found the solution with the help of @Farahmand, here it is: <?php defined('_JEXEC') or die; function empresaBuildRoute(&$query) //Esta función divide la url y se trae las variables. { $segments = array(); if (isset($query['view'])) { $segments[] = $query['view']; unset($query['view']); } if (isset($query['padre'...


2

Try this Goto joomla administrator -> System -> Global configuration -> Here you can enable the sef url and check your url.


2

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=' . $...


1

You can use .htaccess URL Rewrite replacing the numeric segment to something else but you have to make sure your item's alias column is unique in your component's table unless the same URL segments being generated will conflict.


1

I played a bit around with that the last hour and the way you do seems to be right. Maybe you can share all the relevant code here? This could also be related to that current Joomla! issue which results in similar URLs containing /administrator/ even if a frontend URL is generated: https://github.com/joomla/joomla-cms/issues/20070 The release lead of ...


1

There seems to be a bug with the routing in Joomla 3.8.4 which is a known issue and is currently being discussed on Github, here: https://github.com/joomla/joomla-cms/issues/19496 I've seem elsewhere that a quick fix (temporarily) is to replace the following file: libraries/src/Router/SiteRouter.php with the one from Joomla 3.8.3 There is also a pull ...


1

You are not checking the existence of parameter name before using it. Hence PHP shows the notice message. Change your code to if(isset($query['id']) && isset($query['name'])) { $segments[] = $query['id']."-".$query['name']; unset($query['id']); unset($query['name']); } else if(isset($query['id'])) ...


1

My original goal was creating a alias on frontend without any link using Jroute or menu id... But after a lot of search it seems that Joomla cannot do that or if it can it may need some serious change on Router. So instead of messing with Joomla Router (I actually tried) I created a script on my plugin to create a menutype and to save on database a new menu ...


1

Create your URLs like this: echo JRoute::_('index.php?option=com_mycomponent&Itemid='.Itemid.'&aliasid=alias-'.$id); You will want to include the Itemid of your current menu item, makes things cleaner and helps you keep track of where you are. That can be found with: $Itemid = JFactory::getApplication()->getMenu()->getActive()->id; Try ...


1

BuildRoute function gets whatever the information you will pass to it. How you are creating your urls in your component? Like this? $url = JRoute::_('index.php?option=com_mycomponent&view=myview&task=mytask&id=1'); In above case the view parameter is passed with the url structure and hence the BuildRoute function knows how to get the view ...


1

You can not achieve it the way you trying to because if you look at the router code: link that starts with index.php should be passed, not with http(s) The correct way to achieve routing is: JRoute::_('index.php?Itemid=164') If you would like to have absolute sef url you need to prepend root after: JUri::root().JRoute::_('index.php?Itemid=164')


1

You can also use proper way to get full url as: $config = JFactory::getConfig(); $mode = $config->get('force_ssl', 0) == 2 ? 1 : (-1); echo JRoute::_('index.php?Itemid=164',false,$mode);


1

You could try this way: $itemid = 164; $application = JFactory::getApplication(); $menu = $application->getMenu(); $item = $menu->getItem( $itemid ); $link = new JURI( $item->link ); $link->setVar( 'ItemId', $itemid ); echo JRoute::_( $quoteLink, true, -1 ); ?> From JRoute documentation: Routing URLs** The JRoute::_ method translates the ...


1

It is Ok to create hidden menu items for better content managament. But, you have to be sure that Itemid is associated with generated Urls. It is not so obvious how to associate Itemid. Each extension implements its own recipe: A single fixed Itemid Multiple Itemids, one for each available menu option If you have a raw Url, you can look for the main ...


1

Solved the problem by creating a hidden menu for Search component. Here is the link which i followed https://docs.joomla.org/Search_Engine_Friendly_URLs


1

I have recently seen this on a few sites and just discovered that it happens when the site is in offline mode and you are logged in to the frontend. When the site is online and you make up a url you get the standard error page with status code. When the site is offline and you are logged in, you get redirected to /index.php with a 303 see other status code....


1

Disable SEF, and check the Itemid to find which K2 feature is answering the request From my experience, to avoid cat levels, you have to define a menu item for each article "Item" (Create a menu item linking directly to an item in K2). There is no standard way to define all SEF articles to K2 single item feature.


1

Create a new menu called HIDDEN (i.e wont actually be displayed on the site Create a menu item in there to display all the category parents in either list or blog layout. Doesn't matter, just so long as the articles 'tagged' are in a category covered by a menu item. If you just have ONE root category for all items, the one item should be sufficient. Make ...


Only top voted, non community-wiki answers of a minimum length are eligible