Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » location of function

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

Page: 1
Go to End
Author Topic: 892 Views
  • leafchild
    Avatar
    Community Member
    41 Posts

    location of function Link to this post

    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

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: location of function Link to this post

    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.

  • leafchild
    Avatar
    Community Member
    41 Posts

    Re: location of function Link to this post

    Thanks Ryan M,

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

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: location of function Link to this post

    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.

  • leafchild
    Avatar
    Community Member
    41 Posts

    Re: location of function Link to this post

    thanks

    892 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.