Categories
Php SilverStripe

Install Tidy on Ubuntu

Not something big or important, but I just tried several ways to get tidy library on my Ubuntu box, and none other then this worked. Might save some searching to others.

sudo apt-get install php5-tidy

Tidy is recommended for running SilverStripe (not required).

php5 comes with Tidy library preinstalled but it has to be compiled –with-tidy which is sometimes skipped (well, on the box I’m setting up for example).

Categories
CMS Php SilverStripe

Silverstripe 3 Grid Field Config Options

The grid field system in Silverstripe 3 has a number of preset config options – here’s what they do, and what they look like:

No Config

If we don’t add any config options, the grid field just displays a list of items…  We can’t view the record details, or edit anything though…

grid1

$gridfield = new GridField(“RegisterEvents”, “RegisterEvent”, $this->RegisterEvents());
$fields->addFieldToTab(‘Root.Events’, $gridfield);

GridFieldConfig_RecordViewer

 

This option just adds in the ability to click the magnifying glass and view the details of each item – but not edit anything.

grid2

GridFieldConfig_RecordEditor

 

Now we’re starting to get something useful – a list that lets us Add, View, and Remove records…

grid3

GridFieldConfig_RelationEditor

The final option is the Relation Edition set up. This adds features to work with ‘has-many’ and ‘many-many’ relationships.

See our article about Many_Many relations for more details

Custom Config

Or, you can just create an empty configuration, and add the bits you need….

 

Categories
CMS Php SilverStripe

Extending SilverStripe 3 Site Settings

When you first install your SilverStripe site, the ‘Settings’ menu is pretty limited, offering just Title, Tagline, and a choice of templates.

This is fine, but it’s often useful to add other options, such as logo upload, links to facebook, uploading a banner image that appears on every page.

MySiteConfig.php

In your ‘mysite/code/’ folder, create a new file called ‘MySiteConfig.php’, and insert the following text:

This file creates a ‘DataExtension’. A DataExtension, as the name suggests, is used to extend any set of data. You declare the additional databse fields and relations just as you would when creating a new page.

And you use the function ‘public function updateCMSFields {}’ to add the fields to the CMS page, just as you would when creating a new page.

_config.php

In your ‘mysite’ folder, open the ‘_config,php’ file, and add the following line:

This line simple tells SilverStripe to take the ‘SiteConfig’ (the basic settings that already exist) and add ‘MySiteConfig’ to it.

Dev/Build

Go to your site, log in, and add ‘/dev/build’ to the URL – eg ‘mysite.com/dev/build’ to refresh the database.

Now, in the admin area, go to the site settings page and you should see your new options.

Using these fields in the Template

You can now add a logo, banner image, and enter the facebook / vimeo links – the data is stored in the database, but we need to show it on our page.

We do this by adding ‘$SiteConfig.’ in front of the names of the fields. Eg: