Microsoft recently certified the first open source web application to run on Windows Server 2008 R2. That application was SilverStripe, a Content Management System (CMS) originally developed by a team in New Zealand. There are many excellent CMS and other open source web projects but Microsoft saw something they liked in SilverStripe. Ibuildings are certified SilverStripe partners and have been working with it for quite some time, so I thought this was a great time to shed some light on this excellent product.

SilverStripe has put a lot of work into achieving good performance on Windows and IIS, but it also works well on Linux or Mac Servers running open source web server software. There is also a wide variety of databases which SilverStripe supports including SQLServer, MySQL, Postgres and SQLite.

What SilverStripe Offers

Every web site has different requirements, but a CMS application aims to provide a lot of the features needed while at the same time being easy to customise and extend. Database abstraction is particularly suited to a CMS since the schema is fairly simple and based around a page. SilverStripe has an advanced abstraction layer with an elegant syntax that effectively frees you from defining the database schema and instead lets you define models. In this article, I will show you how to define a new page type with custom fields by extending the Page model, and we’ll also take a look at some of the areas that are particularly nicely done by Silverstripe.

Caching is another area that is particularly relevant to CMS systems since viewing of content is hopefully much more common than editing. In SilverStripe, caching can be done on specific areas of a page, or if a page is entirely static, whole pages can be pre-generated. Through the use of static page caching, very high-performance sites can be built.

Undoubtedly, one of SilverStripe’s key strengths from an end user’s perspective is that it offers an easy-to-understand and user-friendly administration interface. The focus of the backend is on editing and publishing content in a clear manner.

Developers who have to extend SilverStripe will find code that is mostly clean Object Oriented PHP that is a pleasure to work with. The core code can be extended in a variety of ways, including inheritance and decorator patterns, as well as by custom widgets and themes. The code base is well tested with a PHPUnit integration that can be used to test any custom code alongside the core.

Installing SilverStripe

Installing SilverStripe on Windows is particularly easy as it is available via the Microsoft Web Platform Installer. If you are on Windows this is a good choice since it will not only install and configure your selection of database, PHP and web server, but it will also install and setup wincache. This PHP extension dramatically improves the performance of PHP applications on Windows, similar to the way APC and other opcode caches improve PHP performance on Linux. Last year techportal published an article by Ivo benchmarking the speed boost provided by wincache looking specifically at SilverStripe and WordPress. The Web Platform installer is available from Microsoft and linked as a download option on silverstripe.org.

If you are not on Windows or don’t wish to use the Platform Installer, you can simply download and extract the latest release from silverstripe.org. The web-based install script will then check the application’s requirements and walk you through the process of configuring your installation.

The SilverStripe User Interface

SilverStripe has a user interface which is similar to modx, which you might be familiar with. If not, it is still fairly easy to familiarise yourself with, as it is designed to be approachable and easy to use.

1. The Site Tree

The site tree lists all the pages currently in the CMS, whether they are published or not. Different colours are used to indicate the current status of a page. As you can see, Pages can be nested into a hierarchy. By default, the top level of the hierarchy is shown in the menu although any page can be excluded from the menu.

2. The Content Edit Section

Content editing is through a tiny mce wysiwyg editor. This allows you to make use of your CSS styles from within the editor.

3. Access tab

The Access tabs allows the setting of which groups of users can view and edit this page.

4. Roles

Roles is the system by which users are assigned to groups which will control their access to the CMS and pages.

Adding a new page type

Once the basic SilverStripe is site set up and you have experimented with the user interface, you can begin to add in your own custom functionality. In SilverStripe, all pages you view are objects of type Page. By default, the installer will have placed the code for this Class at mysite/code/Page.php.

Opening up this class, you will see it is pretty minimal at the moment. All the functionality is located in its parent SiteTree which is part of the code sapphire framework, which Silverstripe is built on.

Editing this file allows you to define your own behaviour that will affect all pages on your site without touching the core code. However, we are going to create a new page type which will inherit from this class. So close this file and create a new file alongside it in the same directory called Speaker.php. Inside this file we will define a class Speaker that extends our Page class, and below it in the same file a class Speaker_Controller which extends the Page_Controller.

Now visit http://yoursite/dev/build

This is the the environment builder for SilverStripe, which amongst other things rebuilds the manifest of classes to include in the CMS. Hopefully you should see some text in blue at dev build. This is SilverStripe automatically altering an enum column in the database to reflect our new Speaker page type.

Now when you revisit the admin section of your site at http://yoursite/admin you should be able to create a page of type Speaker. At the moment though this will just be the same as any other page of your site, since it just inherits from the Page class. We are going to need to add a photo and Talk title field on our Speaker.

The first step to do this is tell SilverStripe about the new columns we will need in the database.

Revisit /dev/build/ and this time you should see some text in green as SilverStripe created some new database tables. You will notice that we did not add a column to hold the image: this is because an image is itself a type of SilverStripe object which we will link to our Page type later.

The next thing to do is to tell the admin interface about our new fields. Create a new method in your Speaker object called getCMSFields.

 

The first line of this method gets the fields added internally by SilverStripe – these fields include the title and Content field. The next line adds a new Text field to the fields list. ‘Root.Content.Main’ describes which tab to put the field on, in this case the Main tab inside the Content Tab. The next two lines rename the Content and Title fields to make the interface a little easier to understand.

To add the photo field, add the relation to your speaker class and add the field inside getCMSFields.

Now adding a new Page of type Speaker should result in an interface like the one below.

So far we have created the interface and database fields to hold our new data. With the code as it is now, when we enter data in the form and upload a photo, it will be stored for us in the database. To view the content on the front end, you will need to create a new template. The default theme installed by SilverStripe is called black candy. Add a file to themes/blackcandy/templates/Layout/Speaker.ss . SilverStripe uses its own templating language which allows you to mix HTML and variables without requiring special tags.

$Photo.SetWidth(150)
Talk: $TalkTitle
Bio: $Content

The first line includes another template file which can contain common layout code. Using PHP style variables such as $TalkTitle and $Photo will call methods called TalkTile() and Photo() on our model and print the output. If these aren’t defined, SiteTree will return columns or relations of that name. This is what is happening in our template.

Modules

Although the number of community-written modules available for SilverStripe is not as large as some other CMS projects, there are many useful ones. These include:

  • Subsites – This module allows you to run several sites from the same SilverStripe code base in a similar way to a Drupal multisite installation.
  • Auth_External – Allows for users to be authenticated against an external service such as LDAP
  • Blog – A fully functioning blog page type.

There are also community-written themes and widgets.

Conclusion

Hopefully this whirlwind tour of SilverStripe has given you an idea of what it is and how it can be used. It has some interesting features which can be used to develop custom CMS functionality in a quick and clean way. As with every platform, however, there is a learning curve to follow. One of the nice things about SilverStripe is that many of the concepts used are based on those of object oriented PHP itself, which will aid developers when approaching it for the first time.