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 /

Understanding Database with Silverstripe


Reply


3 Posts   318 Views

Avatar
Bagzli

Community Member, 37 Posts

28 January 2014 at 1:11pm

Hi guys,

I'm having troubles understanding how to access the database portion with silverstripe. I've coded sites in java, ASP.NET (C#), Ruby on Rails, etc.. I have experience with object oriented design mostly and i'm a little confused how it works with silverstripe.

So here are some basic questions I'm hoping somebody will answer:

1. How are database objects saved? For example lets say I have ArticleHolder and ArticlePage php files, just like in extended tutorial. Are those 2 considered database objects? How can I call them?

2. How would I perform simple queries on these objects, for example I want to sort all the articles that came back by a date field that I have setup. Or how would I grab a value from a text field I've setup called myAmazingField?

So basically I'm trying to understand how database works and how can I control it. Do I call queries or do I use built in prefix methods to have it do what I need it to do.

Avatar
martimiz

Forum Moderator, 1105 Posts

29 January 2014 at 1:29am

Hi

In most cases you'll never have to deal with the actual database itself - all CRUD functionality is handled by the DataObject model class. Pages are in fact special DataObjects, that have a whole lot of extra functionality added, but the basics remain the same. This model allows for very sophisticated queries. Read all about it here:

http://doc.silverstripe.com/framework/en/topics/datamodel

Still, if you really need to, you can use other options, like for instance the DBQuery class. This gives you a bit more freedom, but makes you step outside the Model View Controller setup, making integrating the results somewhat more tricky.

Martine

Avatar
Bagzli

Community Member, 37 Posts

30 January 2014 at 4:16pm

Thank you, that helped a lot.