?
avatar BrainforgeUK
BrainforgeUK
8 Apr 2021

Steps to reproduce the issue

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

Expected result

Value of $link set to:
testsite/index.php/directory

If I access the site with that URL it works, as expected.

Actual result

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.

System information (as much as possible)

PHP 8.0

Additional comments

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

avatar BrainforgeUK BrainforgeUK - open - 8 Apr 2021
avatar joomla-cms-bot joomla-cms-bot - labeled - 8 Apr 2021
avatar infograf768
infograf768 - comment - 9 Apr 2021

Global Configuration : Set Search Engine Friendly URLs to Yes.

avatar brianteeman
brianteeman - comment - 9 Apr 2021

@infograf768 please take another coffee and re-read the post

avatar BrainforgeUK
BrainforgeUK - comment - 9 Apr 2021

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

avatar Fedik
Fedik - comment - 9 Apr 2021

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

public function __construct(SiteApplication $app, AbstractMenu $menu)
{
$search = new RouterViewConfiguration('search');
$this->registerView($search);
parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}

so for your com_mycomponent and index.php/directory?view=directory it need:

$dir = new RouterViewConfiguration('directory');
$this->registerView($dir);
avatar BrainforgeUK
BrainforgeUK - comment - 9 Apr 2021

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));
}

}`

avatar Fedik
Fedik - comment - 9 Apr 2021

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
avatar Fedik
Fedik - comment - 9 Apr 2021

Please close the issue if you have fixed your problem.

avatar BrainforgeUK BrainforgeUK - change - 9 Apr 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-04-09 09:54:46
Closed_By BrainforgeUK
avatar BrainforgeUK BrainforgeUK - close - 9 Apr 2021

Add a Comment

Login with GitHub to post a comment