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?
Thanks
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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?
Thanks
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.
Thanks Ryan M,
Could you show me example, accessing controller B to Page_Controller ?
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:
$this->yourCustomFunction();
or in your template:
$yourCustomFunction
Remember, putting the function in the parent, ie Page.php, will make it available to any pages that extend Page.php.
thanks