Jump to:

23355 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » MyPage class and using magic __call()

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: 568 Views
  • SunboX
    Avatar
    Community Member
    5 Posts

    MyPage class and using magic __call() Link to this post

    Hi,

    i would write something like:

    public function __call($action, $args)
    {
       switch($action)
       {
          case 'edit':
             if(Permission::check('ADMIN') || (is_numeric($this->urlParams['ID']) && $this->urlParams['ID'] == Member::currentMember()->ID))
             {
                $this->Content = $this->EditProfileForm();
                break;
             }
                
          case 'show':
             $this->Content = 'Und hier kommt die Maus...';
             break;
       }
          
       return $this;
    }

    But that doesn't work. Instead i have to write:

    public function edit() { return $this->doAction('edit'); }
    public function show() { return $this->doAction('show'); }

    public function doAction($action)
    {
       switch($action)
       {
          case 'edit':
             if(Permission::check('ADMIN') || (is_numeric($this->urlParams['ID']) && $this->urlParams['ID'] == Member::currentMember()->ID))
             {
                $this->Content = $this->EditProfileForm();
                break;
             }
             
          case 'show':
             $this->Content = 'Und hier kommt die Maus...';
             break;
       }
       
       return $this;
    }

    Why can't i use the __call() magic?

    thx Sunny

    PS:

    I know, i can write something like this:

    public function edit()
    {
       if(Permission::check('ADMIN') || (is_numeric($this->urlParams['ID']) && $this->urlParams['ID'] == Member::currentMember()->ID))
       {
          $this->Content = $this->EditProfileForm();
          return $this;
       }
       return $this->show();
    }

    public function show()
    {
       $this->Content = 'Und hier kommt die Maus...';
       return $this;
    }

    ;o) but the use of __call() would be nice.

    568 Views
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.