Routes to different Controllers for the same Backend Module

Hi,

I’ve a backend module for manipulating our Members.
A Member is just a user, that can log in.
It has a number of props and serves as the parent object for more specialized members:
PersonalMember (natural persons) and CorporateMember (companies) extend Member.
This works fine, so far.
Now, I want to clean up the code:
At the beginning I had it all together in the MemberController (default routing -> neos/energieWinner/members).

The indexAction() renders the list of all members (All kinds). It should be the only action there.

ActionLink in index.html:

<f:link.action package="Eg.Member" controller="PersonalMemberController" action="show" arguments="{member: member}">

When klicking on a line of that list, the respective actions should be handled by the specialized
PersonalMemberController and the CorporateMemberController. They are in the some directory as the MemberController.

So, I enabled routes for my Package (Settings.yaml):

TYPO3:
  Flow:
    mvc:
      routes:
        'Eg.Member': TRUE

Eg.Member/Configuration/Routes.yaml:

#
-
  name: 'Energiegewinner Mitglieder'
  uriPattern: 'neos/energyWinner/{@controller}/{@action}'
  defaults:
    '@package': 'Eg.Member'
    '@format': 'html'

I just want to set different controllers in the action links.

It don’t work.

I see the route in the terminal: (./flow routing:list)

62. neos/energyWinner/{@controller}/{@action}                                   Eg.Member :: Energiegewinner Mitglieder

Can somebody point me to an working example, or give me a hint?

Cheers
Klaus

Hi Klaus,

The issue here is that backend modules aren’t using the normal routing you find in Flow. If you do that and allow access to a backend module using custom routing, you’ll be bypassing the backend module logic including security and navigation.

Instead what you need to do is to register the other controllers as submodules of your main module and link using the <neos:module.link /> view helper which accepts a “path” argument along with normal arguments like you’re used to.

Hope this helps.

Regards,
Aske

Hi Aske,

thank you for the information.
Unfortunately this module is already a subModule. It seems, that a subModule has to have a label.
I never saw a subModule definition with more than one Controller defined. Is this possible?
If the logic is: One Submodule -> One Controller, it would be OK for me.
This Controller grows a little bit fatter than normally, because it has to work on 3 Domain Models.

Have a nice week!
Klaus

All modules can have submodules, even modules already defined as submodules. There’s no difference except the menu hierarchy. One advantage that it already is a submodule is that it’s submodules wouldn’t be shown in the module menu as it only shows the top two levels.

And no one module equals one controller. Regardless this shouldn’t be an issue for you.

Management module (/neos/management/) – visible in module menu
…Sub module A (/neos/management/a/) > Controller A – visible in module menu
…Sub module A1 (/neos/management/a/a1) > Controller A1 – not visible in module menu
…Sub module A2 (/neos/management/a/a2) > Controller A2 – not visible in module menu

Then use path=“management/a/a1” to link to A1 from A or A2.

Thank you again Aske for that great respose!

This is exactly what I wanted to achive.
In a meeting today, we decided to introduce even a third type of Member.
So it really came in a handy for me.

This helped me a lot Aske!

Cheers
Klaus

1 Like

Can’t foreward() - or - redirect() to an other module controller.

From the Settings, Templates and ViewHelper I’ve got it running:
The MemberController (parent) only has the indexAction(), nothing more.
In the index.html I use:

<neos:link.module path="energyWinner\members\personalMembers" action="edit" class="neos-button neos-button-primary" arguments="{member: member}">Bearbeiten</neos:link.module>

That works fine and the PersonalMemberControllers editAction gets invoked and renders Module/Member/PersonalMember/Edit.html

Edit.html contains a link to the PersonalMemberControllers updateAction.

Update also works. At the end of the updateAction() I’d like to redirect() or forward() to the indexAction of the MemberController (parent) like:

    $this->redirect('index', 'Module\Member\Member', 'Eg.Member', null,0,200);
    //$this->redirect('index', 'members');
    //$this->forward('index', 'MemberController', 'Eg.Member');

I did 20 Variations of this lines, but can’t get it to work.
What’s the magic spell here?
Neos allways try to use (error message) PersonalMember/Index.html, but never Member/Index.html.

Klaus

Hi again,

Glad it helped.

I understand it’s difficult, and there is certainly a magic spell needed here. Unfortunately the module concept is not really polished, so there’s no helper classes to achieve this yet.

However here’s the magic formular:

$this->uriBuilder->setRequest($this->controllerContext->getRequest()->getMainRequest());
$arguments = ['module' => 'management/workspaces', 'moduleArguments' => ['@action' => 'show', 'workspace' => 'user-admin']];
$this->redirect('index', 'Backend\Module', 'Neos.Neos', $arguments);

You can skip the moduleArguments part if you don’t need to specify a different action or parameters.

Make sure to use a redirect instead of a forward to avoid potential issues.

Regards,
Aske

Also as a bonus, if you want to have your module on the top level (next to management and administration), but don’t the submodules to appear in the menu, there’s a hideInMenu option you can set on the submodules to hide them.

Thanks again Aske!

Now it works like expected.

I think, it would be nice to have a convenience function like “redirectToModule()” in the AbstactModuleController.

For my purpose that’s absolutely fine.
Our modules now integrate perfectly in the Backend.

Have a nice day
Klaus

2 Likes