Joomla Asked by Lecraver on January 21, 2021
I am creating my own component.
Is it possible to transform:
Route::_('index.php?option=com_toto&view=tutu')
into /somealiasinmenu
?
(This alias can be found in a menu in the backoffice.)
I can do this:
When I click on listAlias, I can edit one row. With my router I have this url:
/listAlias/formviewname/123
but I’d like this url /formAlias/123
How can I do that?
Here is my router.php:
function TotoBuildRoute(&$query)
{
$segments = array();
if(isset($query['view'])){
$segments[] = $query['view'];
unset($query['view']);
};
if(isset($query['id'])){
$segments[] = $query['id'];
unset($query['id']);
};
return $segments;
}
function TotoPlaceParseRoute($segments)
{
$vars = array();
if ($segments[0] === 'formviewname') {
$vars['id'] = (int)strstr(end($segments), ':', true);
}
$vars['view'] = $segments[0];
return $vars;
}
If I'm understanding you correctly, you have 2 menuitems on your site which have links /formAlias
and /listAlias
, and when you form an SEF URL using Route:_()
then it gives you the wrong link; is that correct?
The way I believe Joomla routing works is that when you supply the parameters to Route::_()
it goes through the site menuitems to compare the link attribute of each menuitem with the parameters you specify in your Route::_()
call.
If it finds an exact match then it bases the SEF URL on the alias of that menuitem.
If it doesn't find an exact match, then the choice which Joomla makes will appear more random; I think the menuitem which the user is currently on will have a bearing.
Regardless of that, you can specify which menuitem Joomla should use in one of two ways (that I know of):
Itemid=xxx
parameter in your Route::_()
call (Itemid
is the id of the menuitem you want to use)preprocess()
function.If you want to use the second option then there is an example in https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_Associations in the Custom Router section, where the code checks if the menuitem associated with the Itemid which Joomla routing has provided has the right language, and if not it tries to find a better menuitem, with the correct language.
You would need to do a similar thing to decide whether your formAlias or listAlias menuitem is more appropriate in each particular case. There is a guide to using the Joomla menuitem API at https://docs.joomla.org/Menu_and_Menuitems_API_Guide
Answered by Robbie Jackson on January 21, 2021
1 Asked on January 6, 2022 by user3533235
1 Asked on December 30, 2021 by mano-meter
2 Asked on December 19, 2021
2 Asked on December 11, 2021
0 Asked on December 11, 2021 by sandro-antonucci
1 Asked on November 27, 2021
error handling extensions joomla 3 x server response time update
2 Asked on November 27, 2021 by lovntola
2 Asked on November 25, 2021
1 Asked on November 20, 2021
1 Asked on November 19, 2021 by matthiasdunkel
1 Asked on November 5, 2021 by fruit_alchemist
2 Asked on September 5, 2021 by user2363969
3 Asked on September 5, 2021 by jamesmandatory
0 Asked on September 5, 2021 by kaballo
1 Asked on September 5, 2021 by gart
1 Asked on September 5, 2021 by user1616338
1 Asked on September 5, 2021 by ygiorgos
2 Asked on September 5, 2021 by okisan
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP