Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Beginner: Help on how to use your own classes?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1079 Views
  • jdi
    Avatar
    Community Member
    34 Posts

    Beginner: Help on how to use your own classes? Link to this post

    Hey,

    I've been hunting a round for something to get my foot in the door.

    Can someone help me work out how to use my own classes or other classes (e.g something from phpclasses.org) in my silverstripe modules?

    Even a quick outline of whats required is fine, I don't need exact details

    Cheers.

  • joshy
    Avatar
    Community Member
    57 Posts

    Re: Beginner: Help on how to use your own classes? Link to this post

    Hiya,

    You can use them just as you would any other class and then simply 'require' them and use as normal, ie:

    require './external_class.php';

    class NewPage_Controller extends Page_Controller {

    function init() {
    $external = new ExternalClass();
    $external->doSomething();
    return $this;
    }

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Beginner: Help on how to use your own classes? Link to this post

    Or if you put the code in your mysite folder (well any module folder) SS will automatically include the PHP class for you as long as its somewhere in the app.

    Eg if you have someclass.php in mysite/code/ you can straight away reference that class without any require lines.

  • jdi
    Avatar
    Community Member
    34 Posts

    Re: Beginner: Help on how to use your own classes? Link to this post

    Awesome, thanks for being so helpful. I'll give it a shot!

    1079 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.