Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » How to get a controller from it's page?

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: 456 Views
  • tfliam
    Avatar
    Community Member
    20 Posts

    How to get a controller from it's page? Link to this post

    Currently I am using codes below to get a page's controller from a page:

    //check page existence
    $pagename = 'ContactPage';
    if($page = DataObject::get_one($pagename)) {

    //check method existence
       $page_controller = $pagename . '_Controller';         
       $page_controller = new $page_controller;                                    

       if ($page_controller->hasAction('confirmationEmail')) {      
          return Controller::join_links($page->AbsoluteLink(), 'confirmationEmail');                     
       }                        

    }            

    Is there any more effiecient method?

    456 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.