Add MenuRules to your component router. Make sure SEF URLs turned off.
$this->attachRule(new JComponentRouterRulesMenu($this));
Create menu item for your form page with the route something like this
$link = 'index.php?option=com_communitysurveys&task=survey.add';
Add controller which extends JControllerForm
Call parent::add
parent::add()
The JControllerForm class redirect to the new page with the itemid corresponding to the form menu attached but with the following format.
/index.php?option=com_communitysurveys&view=form&layout=edit&**Itemid[0]=110**&return=aHR0cDovL2xvY2FsaG9zdC9qMy8
Since ItemId in the URL is an array, it throws errors on subsquent pages. like below.
Notice: Array to string conversion in D:\xampp\htdocs\j3\libraries\src\Helper\ModuleHelper.php on line 407
The ItemId=110 was added and no errors on subsequent pages
Itemid[0]=110 was added
Joomla 3.x
Labels |
Added:
?
|
Do we have a way to see this error in core components? Looking at this, I'm unsure if this is an issue with the router. Shouldn't the redirect URL is built in getRedirectToItemAppend method of the controller like how we do in Joomla core, like this https://github.com/joomla/joomla-cms/blob/4.0-dev/components/com_content/src/Controller/ArticleController.php#L284 ?
Note: This issue occur only when you have a menu item for the form page, with the URL in menu something like this - index.php?option=com_communitysurveys&view=form&layout=edit
Now, in my controller, getRedirectToItemAppend returns the value &layout=edit&Itemid=484&return=aHR0cDovL2xvY2FsaG9zdC9qMy8=
If I add var_dump in the FormController
class just before the edit screen redirect set, the redirect value prints null. So the redirect value was not yet set.
Which is then passed to JRoute::_ in the FormController
class
// Redirect to the edit screen.
$this->setRedirect(
\JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(), false
)
);
After this, if I print protected redirect value it shows like this
protected 'redirect' => string '/index.php?option=com_communitysurveys&view=form&layout=edit&Itemid[0]=2604&return=aHR0cDovL2xvY2FsaG9zdC9qMy8=
So definetely, this is not an issue with the getRedirectToItemAppend
. JRoute
is changing the ItemId
to array when the menu item exists.
Following rules are added in the router file.
$this->attachRule(new JComponentRouterRulesMenu($this));
$this->attachRule(new JComponentRouterRulesStandard($this));
$this->attachRule(new JComponentRouterRulesNomenu($this));
Hope this helps.
Please confirm this is Joomla 3 ?
Yes, Joomla 3 latest version as on date.
Please note that I can reproduce this issue in Joomla 4 as well, precisely all Joomla3/4 versions using the new Joomla router.
P.S. If there is no menu item created, the issue won't occur.
I'm guessing you have defined the view configuration for your form view to take an ID. Remove that and the error should go away
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-12-07 11:34:26 |
Closed_By | ⇒ | Hackwar | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
I looked up the code again and yes, that is indeed the problem. This is not a bug on Joomlas end. Closing this one.
ping @Hackwar