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


Reply


5 Posts   953 Views

Avatar
leafchild

Community Member, 41 Posts

16 February 2011 at 1:13pm

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

Avatar
Ryan M.

Community Member, 309 Posts

16 February 2011 at 5:28pm

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.

Avatar
leafchild

Community Member, 41 Posts

17 February 2011 at 9:47am

Thanks Ryan M,

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

Avatar
Ryan M.

Community Member, 309 Posts

17 February 2011 at 12:45pm

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.

Avatar
leafchild

Community Member, 41 Posts

17 February 2011 at 12:56pm

thanks