Jump to:

23576 Posts in 19403 Topics by 2893 members

General Questions

SilverStripe Forums » General Questions » public, protected, private and allowed_actions

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

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

Page: 1
Go to End
Author Topic: 1046 Views
  • DNA
    Community Member
    24 Posts

    public, protected, private and allowed_actions Link to this post

    The functionality around public, protected and private methods in a controller seems a little weird to me...

    Love that methods are available to urls /home/method, however think that only public functions should be, currently protected also work, and the controller thinks that private ones exist and tries and then fails with an error:
    Uncaught Exception: Object->__call(): the method 'yo3' does not exist on 'Page_Controller'

    public function yo1() {
       return $this;

    protected function yo2() {
       return $this;

    private function yo3() {
       return $this;

    Love that methods are available to templates and love that only public or protected methods are, however private functions fail with the same error as above.

    Surely in both cases private functions should fail the same way as calling a method that does exist (url=404, template=no output).

    Secondly it seems that $allowed_actions is some remedy here, however if there is documentation for this I can't find it (aside from what's in code). Doesn't help that documentation search ignores underscores and treats it as a space. So you might as well just have searched "allowed actions".

  • Willr
    Forum Moderator
    5511 Posts

    Re: public, protected, private and allowed_actions Link to this post

    Allowed actions is the way to go here rather than private methods.

    static $allowed_actions = array('yo1', 'yo2');

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.