1

I'm trying to do a "quick" fix to J3 components so they work in J4 until I can re-code in the new structure ready for J5. Now that I've set the scene, I'm stumbling on getting the Menu URL that was last selected before performing some updates to a record in the frontend.

Old J3 way I worked this in the controller was:

$menu = Factory::getApplication()->getMenu()->getActive();
$url  = (empty($menu->link) ? 'index.php?option=com_mycomponent&view=multiviews' : $menu->link);
$this->setRedirect(Route::_($url, false));

Now using this in an install of J4 keeps dumping me back to default home page. Any and all guidance appreciated. Glenn

0

Ok, so a work around for me is to have the "collection" of the Menu id in the view template saved to session and then brought back in the controller where I need it (ie been over to another form view and submitted etc).

In the View:

$menu = Factory::getApplication()->getMenu()->getActive();
$Itemid = $menu->id;
Factory::getApplication()->setUserState('com_mycomponent.menu.Itemid', $menu->id);

In the Controller:

$Itemid = Factory::getApplication()->getUserState('com_mycomponent.menu.Itemid');
$this->setRedirect(Route::_('index.php?option=com_mycomponent&view=multiviews&Itemid='.$Itemid, false));

I'm sure there is a nicer way to do this, so if anyone can shed some light on it for me, much appreciated. I have converted a component into the new structure and there is no need for this, all handled within the CMS framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.