Jump to:

22970 Posts in 11572 Topics by 2823 members

General Questions

SilverStripe Forums » General Questions » Executing a class method from the URL (for logout method)

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 2
Go to End
Author Topic: 2041 Views
  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Executing a class method from the URL (for logout method) Link to this post

    AFAIK custer, Decorators won't work in this sense for controllers. I don't believe it is setup to check whether functions exist on the extensions. I ran into trouble with this myself. Haven't dug much deeper into it.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Executing a class method from the URL (for logout method) Link to this post

    AFAIK custer, Decorators won't work in this sense for controllers. I don't believe it is setup to check whether functions exist on the extensions. I ran into trouble with this myself. Haven't dug much deeper into it.

  • cuSSter
    Avatar
    Community Member
    56 Posts

    Re: Executing a class method from the URL (for logout method) Link to this post

    So for this issue, the only workaround is to hack the core and add the function that you post and add that function in the $allowed_actions? Thanks by the way for the quick response.

  • cuSSter
    Avatar
    Community Member
    56 Posts

    Re: Executing a class method from the URL (for logout method) Link to this post

    By the way, I'm working on the 2.4.0 version of SilverStripe.

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Executing a class method from the URL (for logout method) Link to this post

    I'd like to add to this thread, because I was looking for a similar logout solution, since the ?BackURL doesn't work on Security/logout.

    My problem was that I needed the logout action to work anywhere and I didn't want to hard-code it into the template because the base href will direct it to domain.com/logout instead of domain.com/page/logout. Ergo, my solution was:

    in Page.php -> Page_Controller

    public function LogoutLink() {
          return $this->Link('logout');
       }
       
       function logout() {
          if($mem = Member::currentUser()) {
             $mem->logOut();
          }
          return Director::redirect("home/");
       }

    Simply insert $LogoutLink anywhere you have a logout link on your site. It'll log the user out no matter what page they were on.

    2041 Views
Page: 1 2
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.