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.

General Questions

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

How to get a controller from it's page?


Reply

487 Views

Avatar
tfliam

4 May 2012 at 3:01am (Last edited: 4 May 2012 3:56pm), Community Member, 20 Posts

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?