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.

We've moved the forum!

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.

Data Model Questions /

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

Beginner: Help on how to use your own classes?


Go to End


4 Posts   2154 Views

Avatar
Jakxnz

Community Member, 36 Posts

28 May 2010 at 10:23pm

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.

Avatar
joshy

Community Member, 57 Posts

29 May 2010 at 11:44am

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;
}

Avatar
Willr

Forum Moderator, 5523 Posts

29 May 2010 at 2:39pm

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.

Avatar
Jakxnz

Community Member, 36 Posts

29 May 2010 at 10:11pm

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