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

Best place for a common function


4 Posts   386 Views


6 March 2012 at 11:04pm Community Member, 9 Posts

I have two functions which I want to use in both a controller (which is called in template), and a DataModule.

It's only two functions, instead of duplicating the code, whats/where is the best place to put these two functions?


7 March 2012 at 8:20am Community Member, 115 Posts

Page.php Page_Controller

Not sure what DataModule is but if it extends the Page class then it should be accessible in your other two classes.


7 March 2012 at 1:50pm Community Member, 23 Posts

See this thread for some solutions:


8 March 2012 at 8:14pm Community Member, 9 Posts

Thanks for the replies.
I don't feel like the functions belong in the main Page controller - as other controllers don't need these functions.

Maybe I could create a separate class with static functions (or normal).