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

location of function


5 Posts   910 Views


16 February 2011 at 1:13pm Community Member, 41 Posts

Hi I'm new to SS.

I have many contact forms at different pages and using same function.

I don't want to write same function on every controller.

Where I can put the function that all controller can access to it?


Ryan M.

16 February 2011 at 5:28pm Community Member, 309 Posts

Put it in code/Page.php under Page_Controller. As long as your contact form pages extend the Page class, they will inherit your function.


17 February 2011 at 9:47am Community Member, 41 Posts

Thanks Ryan M,

Could you show me example, accessing controller B to Page_Controller ?

Ryan M.

17 February 2011 at 12:45pm Community Member, 309 Posts

I'm not sure what you mean... do you want me to write an example of how to call the function from another page?

All you would need to do is either use this in your page's controller:


or in your template:


Remember, putting the function in the parent, ie Page.php, will make it available to any pages that extend Page.php.


17 February 2011 at 12:56pm Community Member, 41 Posts