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

Calling controller function always delivers error 403


Go to End


14 Posts   3962 Views

Avatar
MarioSommereder

Community Member, 107 Posts

10 March 2015 at 7:14pm

Hej there.

I'm trying to call a function inside my controller, returning a simple value/string.

I tried via browser address and AJAX call, using the URL "/QuizPage_Controller/checkQuizForm":

class QuizPage_Controller extends Page_Controller {
	private static $allowed_actions = array(
		'checkQuizForm'
	);
	public function checkQuizForm() {
		return 'form checked';
	}
}

The result is alway a 403 forbidden. Even when I'm logged in as an admin.

What do I do wrong? Can't be that hard...

Thanks, Mario

Avatar
Devlin

Community Member, 344 Posts

10 March 2015 at 9:56pm

You need to ?flush the site to have the site recognize your altered $allowed_actions setting.

Avatar
MarioSommereder

Community Member, 107 Posts

10 March 2015 at 10:32pm

I did that, without any effect.

Avatar
Devlin

Community Member, 344 Posts

10 March 2015 at 11:49pm

Maybe you've permission in place for this page?

Avatar
wmk

Community Member, 87 Posts

11 March 2015 at 12:53am

Hey Mario,

what are the logs saying? SS error log or webserver error log? Also I'd switch to dev mode to see more than just a forbidden message.

Does calling the controller directly work? e.g. http://mysite.com/QuizPage_Controller/checkQuizForm ?

Cheers, Werner

Avatar
MarioSommereder

Community Member, 107 Posts

11 March 2015 at 2:55am

I did not check the logs yet, but I am admin and logged in. Also the site runs in dev mode. The 403 comes, when I try via Ajax. When trying to load the function directly, the page says, that the page is not public yet and I have to log in as someone else to see the unpublished content.

This is strange and I'm pretty sure there is just one little thing to change.

Avatar
Nightjar

Community Member, 28 Posts

11 March 2015 at 3:21am

This does sound strange.
Since this is a page type though it is probably worth checking:

  1. in the cms whether or not Access is limited
  2. whether you have some stricter settings in the model's canView()
  3. That the page is published

:)

Avatar
dhensby

Community Member, 253 Posts

11 March 2015 at 3:32am

If you're on a 3.x site you can't access the controller via the URL without setting up a rule on the director.

mysite/_config/routes.yml

---
Name: mysiiteroutes
After: 'framework/routes#coreroutes'
---
Director:
  rules:
    'QuizPage_Controller//$Action/$ID/$OtherID': 'QuizPage_Controller'

Go to Top