Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Controller action without page


Go to End


3 Posts   1231 Views

Avatar
Rodskagg

Community Member, 26 Posts

1 October 2015 at 1:53am

Edited: 01/10/2015 2:07am

Is it possible to have a controller action that isn't associated with a specific page? I have added this to my routes.yml:

Director:
rules:
'donations/$Action/$ID/$Name': 'DonationController''

And have created a DonationController with an action called donation, so that I should be able to post to /donations/donation, but it doesn't seem to work.

The ideal solution would be to have an action called donation in the root, and be able to post to it using "/donation" as the URL.

Avatar
Pyromanik

Community Member, 419 Posts

1 October 2015 at 2:38am

By default index() is the action executed. You can impement that to have donations/ return something.
Basically this: https://docs.silverstripe.org/en/3.1/developer_guides/controllers/introduction/

Or you can implement handleAction to customise the logic.
But the easiest way is to specify the function in url_handlers configuration.
https://docs.silverstripe.org/en/3.1/developer_guides/controllers/routing/#url-handlers

Avatar
Rodskagg

Community Member, 26 Posts

1 October 2015 at 2:43am

Great, thanks! I had forgotten to add the index() method/action.