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   1201 Views

Avatar
jdi

Community Member, 34 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, 5513 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
jdi

Community Member, 34 Posts

29 May 2010 at 10:11pm

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