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.

Data Model Questions

Beginner: Help on how to use your own classes?


Reply

4 Posts   1174 Views

Avatar
jdi

28 May 2010 at 10:23pm Community Member, 34 Posts

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

29 May 2010 at 11:44am Community Member, 57 Posts

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

29 May 2010 at 2:39pm Forum Moderator, 5511 Posts

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
jdi

29 May 2010 at 10:11pm Community Member, 34 Posts

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