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 );
This has worked wonders for me.
the output from JRoute will depend on what you feed it.
might return something else than
In fact if you have a menu item category blog listing for catid=5, the latter might give you the menu-url (I ...
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 ...
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);
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 ...
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.
$base_url = 'index.php?';
$parameter = array('id'=>'1',
$base_url .= http_build_query($parameter);
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&...
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 ...
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.
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 ...
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 ...
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.
I found the solution with the help of @Farahmand, here it is:
defined('_JEXEC') or die;
function empresaBuildRoute(&$query) //Esta función divide la url y se trae las variables.
$segments = array();
$segments = $query['view'];
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=' . $...
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.
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:
The release lead of ...
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:
I've seem elsewhere that a quick fix (temporarily) is to replace the following file:
with the one from Joomla 3.8.3
There is also a pull ...
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'];
else if(isset($query['id'])) ...
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 ...
Create your URLs like this:
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;
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 ...
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:
If you would like to have absolute sef url you need to prepend root after:
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 ...
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....
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.
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 ...