SilverStripe: PHP on Rails

| Posted | Comments | , ,

In my last post, I talked about a few problems I have with MODX. In this post, I'm going to introduce a CMS called SilverStripe that I believe can help address some of the problems that developers might have with MODX.

SilverStripe is a content management system developed by SilverStripe Limited, a web development company that has been around since 2000. The CMS originally started as a proprietary system but, with the 2.0 version, the company decided to release it as open source in 2007. Since then, a 3.0 version was released in 2012 with some very welcomed changes. I appreciate the fact that the SilverStripe is a web development company because it means that, through the use of their own system with client sites, they can review how clients use the system and improve useability.

SilverStripe is more of a framework than a CMS. The core of SilverStripe is a framework known as Sapphire, which can be used much in the same vein as other PHP frameworks like CodeIgniter and FuelPHP, allowing applications to be built using no CMS at all. In fact, the CMS portion and every other addon to SilverStripe are nothing more than modules added onto the framework, which lends itself to being highly extensible.

Everything in the framework follows a heavy MVC model. When I showed this system to a seasoned Rails developer, he looked at it and said, "That's Ruby on Rails!". Yes, Rails developers will be pleased to find that there are similarities between Ruby on Rails and SilverStripe.

Easy Data Modeling

When I sit down to start developing a site, the first thing I do is try to get a handle on how the information is structured and how it might be managed. Not only does SilverStripe make this easy but the database itself will reflect your data model to the letter.

Both the model and controller classes are handled in a way that makes it easy to extend any PHP class in the system however you'd like. The two main classes that you're most likely to use in the system are the DataObject and Page classes. The DataObject class is the default class that is used to manage every data model in the system. In fact, the Page class is just an extension of the DataObject class. For every class you create, you'll likely extend off of either the DataObject or Page class depending on how you'll use the data.

Every class you create can have its own set of relationships with other classes: one to many, many to one, many to many, you name it. Within any class you can easily filter and return whatever information you want. In most cases you don't have to write a lot of code because the management of relationships is handle automatically for you. The best part of this is that the classes of information you create in the system are reflected in the database in a normalized manner. Any DataObject classes you create will have a table with the same name in the database with index tables created for many to many relationships. It's as simple as that. No ambiguity between your model and how it's stored.

And here's the kicker: SilverStripe manages the database for you! With a simple URL command, any changes you make to your data model will be reflected in the database automatically. The neat part of this is that it's done in a non-destructive way. If you decide to add, edit, or delete a field name or table, SilverStripe will update the database in a way so that none of your data gets destroyed. You might need to go in and do some maintenance to the database away from SilverStripe but, aside from that, SilverStripe does its best not to do anything destructive to your data.

Quick Interfaces Using Scaffolding

Models are handled in a way that is not only easy but allows for quick scaffolding for easy management of the data from within the SilverStripe administration UI. This is the part that completely blew me away. I was amazed at the fact that I can give SilverStripe a model and, with a few lines of code, can have a complete way to administrate all the information from within the UI. Even complex data models can be scaffolded quite easily! Amazing stuff!

Just like MODX components, you can create stand-alone areas of the CMS for managing data. However, unlike MODX, the management of information from within pages is not only easier but is managed in a way that accurately reflects your data model.

For instance, as mentioned in my previous post, imagine you have a Staff model that is attached to a specific Staff page. In SilverStripe, this is as easy as creating a StaffHolder page that has a one-to-many relationship with a Staff model. Whenever you set a page with the StaffHolder template, SilverStripe will automatically create an extra tab called Staff where you can easily add individual records for each staff member. This information can then be easily parsed and used from anywhere on the site.

While this is a simple example, you can create even more complex relationships with your data and implement them in a way that makes it easy for your clients to manage the information within the UI. Not only does this empower your client with the ability to manage their data more effectively, it can be done very easily with not a lot of code and/or knowledge. All it requires is solid knowledge about PHP classes.

Easy Templating

Just like MODX and Rails, management of templates and views is easy. The management of views are very similar to how Rails works in that each view reflects the class that is responsible for the view. Simple placeholders are used for information like the title, content, and other data related to each page or dataset. Logic can be added to a view to help facilitate things like if statements, loops, menus, and other bits of logic.

Unlike MODX though, you can't manage your views from within the CMS. All view files are managed on the file system using various files with a .SS extension. In fact, all files related to the programming of a site are managed on the file system. The only thing that is managed using a database and the UI is the content itself. Upside of this is that all view, classes, and other files can easily be managed with a versioning system like SVN or Git.

Good Documentation, Great Community

When I first started to dive into SilverStripe, I picked up their book SilverStripe: The Complete Guide to CMS Development. Granted, this is an old book. It was written in 2009 and covers an older 2.3 version of SilverStripe. Even then, you can still learn a lot about the philosophy of SilverStripe as well as the basics of how the system works. Through the use of a step-by-step tutorial format, you can quickly get a good understanding of how data modeling, scaffolding, objects, and templates work, all the fundamentals required to build great websites. Still, it would be nice to see a second edition of the book that covers the new 3.0 version and goes farther in the exploration of the system.

Aside from that, the SilverStripe open source site has fair amount of documentation on the system and API, including short tutorials and howto's using the new 3.0 system.

But what truly makes SilverStripe great is the community. Like MODX, SilverStripe has a vibrant community of talented developers contributing to the project and writing all kinds of modules to extend the system in infinite ways. A short visit to GitHub will show you an extensive list of SilverStripe related resources.

From Amazing to Awesome

To give you a taste of just how awesome SilverStripe can be, take some time to visit the SilverSmith project. This addon by Aaron Carlino (AKA UncleCheese) for SilverStripe allows you to quickly and easily write tons of code with just one command. In fact, just watch the videos about the SilverSmith CLI and the links off the SilverSmith project site. My jaw literally dropped! Imagine scaffolding your entire site with just a YAML file and a text file. It basically allows you to do what would take you a few hours to do and do it in just 30 minutes. Insane!

While the CLI is in alpha, the best is yet to come. Aaron has plans of building a native Mac app that allows for visually building your initial data model as well as adding the ability to use plugins for direct integration of other SilverStripe modules. I can't wait!

So, there you have it! A fairly decent review of SilverStripe and it's benefits. Is it a full replacement for MODX? Maybe. Is it perfect? No. There are definitely some areas that could use improvement. But, even then, it's still a great system and very useable in a production environment. Try it and decide for yourself. For Rails developers looking for a solid solution with PHP, SilverStripe might just be the ticket! :)