In code (menu ID is 101)
$link = JRoute::_('index.php?Itemid=101');
Simple component, no router class in the component, has following view:
src/View/Directory/HtmlView.php
tmpl/directory/default.php
tmpl/directory/default.xml (only contains layout, no other parameters)
Create a menu item.
Alias : directory
Menu Item Type : Directory
Link (auto generated) : index.php?option=com_mycomponent&view=directory
Value of $link set to:
testsite/index.php/directory
If I access the site with that URL it works, as expected.
Value of $link set to:
testsite/index.php/directory?view=directory
I do not expect to see the view parameter.
If I access the site with that URL it also works, not unexpected.
PHP 8.0
If I create another layout (notdefault) and add a menu item for that layout I get this
testsite/index.php/directory?view=directory&layout=notdefault
@infograf768 please take another coffee and re-read the post
Search Engine friendly URLS already set to Yes.
Set to No
index.php?option=com_mytest&view=directory&Itemid=101
Set to Yes
index.php/directory?view=directory
It sounds like com_mycomponent
missing the router, or the router missing RouterViewConfiguration
maybe can take as example com_content
router or com_finder
as very basic
joomla-cms/components/com_finder/src/Service/Router.php
Lines 35 to 45 in 03c1bf1
so for your com_mycomponent
and index.php/directory?view=directory
it need:
$dir = new RouterViewConfiguration('directory');
$this->registerView($dir);
The component is missing Service/Router.php
Also had to register the router factory in services/provider.php
Had assumed that without the router the default behaviour would suffice.
The minimum router class which resolves the issue is below.
I assume for completeness best to uncomment the commented lines.
Also add a loop to run through the view layouts and register them dynamically - can then edit the views without having to manually add registerview lines.
`class Router extends RouterView
{
public function __construct(SiteApplication $app, AbstractMenu $menu)
{
//$this->registerView(new RouterViewConfiguration('directory'));
parent::__construct($app, $menu);
//$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
//$this->attachRule(new NomenuRules($this));
}
}`
For correct work you need all 3:
$this->attachRule(new MenuRules($this)); // Search for correct Menu Itemid
$this->attachRule(new StandardRules($this)); // Parse/Build if menu exits
$this->attachRule(new NomenuRules($this)); // Parse/Build if there no menu exits
Please close the issue if you have fixed your problem.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-04-09 09:54:46 |
Closed_By | ⇒ | BrainforgeUK |
Global Configuration : Set
Search Engine Friendly URLs
to Yes.