SilverStripe 3 _config cheat sheet

Posted by Neil Berry on 13 June 2013 | 924 Comments

SilverStripe is my favourite CMS and one I absolutely love working with due to its flexibility, customisation and usability for clients. For each of my SilverStripe projects, there are a number of configuration options I find myself reusing time and time again so I've put together a small cheat sheet to use for your _config file under the mysite folder.

It should save time and, if anything, saves referencing back to your previous projects to find snippets of code. Hopefully it'll be useful for other developers as well.

This list is by no means all you can configure in the config file but serves as a great starting point for all your projects. I'd welcome any other ideas or additional config options you recommend so please add your suggestions in the comments.

// change mysite to name of your site
global $project;
$project = 'mysite';

// your db config details
global $databaseConfig;
$databaseConfig = array(
"type" => 'MySQLDatabase',
"server" => 'localhost',
"username" => 'yourusername',
"password" => 'yourpassword',
"database" => 'yourdbname',
"path" => '',

// Set the current theme


// Set the site locale

// enable nested URLs for this site (e.g. page/sub-page/)
if (class_exists('SiteTree')) SiteTree::enable_nested_urls();

// enable search

// add custom site config to remove the theme
DataObject::add_extension('SiteConfig', 'CustomSiteConfig');

// generate an error log file
SS_Log::add_writer(new SS_LogFileWriter('directorytoyoursite/errors.log'), SS_Log::NOTICE, '<=');

// email error logs to an email address
SS_Log::add_writer(new SS_LogEmailWriter(''), SS_Log::ERR);

// set a default admin account
Security::setDefaultAdmin("", "yourpassword");

//Set the admin email address

//Set to CC all emails to

//Set the CMS application name, logo and loading image
LeftAndMain::setApplicationName("My application");
LeftAndMain::setLogo("themes/MyTheme/images/CMSLogo.png", "margin-top: -3px;");

// Sort assets folders and files alphabetically
File::$default_sort = 'Name';
Folder::$default_sort = 'Name';
Image::$default_sort = 'Name';

// Set comments to be moderated before going live
Commenting::set_config_value('SiteTree', 'require_moderation',true); // settings for the HtmlEditorConfig HtmlEditorConfig::get("cms")->setOptions(array( 'valid_elements' => "@[id|class|style|title],#a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align],-sub[class],-sup[class],-blockquote[dir|class],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align|name],address[class|align],-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class]", 'extended_valid_elements' => "img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap],iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]" ));

Post your comment


  • hi,

    only changed the line error_log to ...

    // Errors logging
    ini_set("display_errors", "Off");
    ini_set("log_errors", "On");
    ini_set("error_log", "../logs/application-php-error.log");
    SS_Log::add_writer(new SS_LogFileWriter('../../logs/application-ss-error.log'), SS_Log::WARN, '<=');

    Note: need create folder "logs" on root.

    Posted by pouic, 26/06/2013 1:29pm (10 months ago)

  • Thanks for the advice Nicolaas, that's a big help :)

    Posted by Neil Berry, 17/06/2013 1:45pm (10 months ago)

  • Hi

    Here is what I would change:

    * MySQLDatabase::set_connection_charset('utf8'); - remove it, I think this is set like this by default? Not sure about this, but worth checking.

    * if (class_exists('SiteTree')) SiteTree::enable_nested_urls(); - the if statement is unlikely to be needed.

    * you only need to log and email the errors on the live site, not on the test / dev site ...

    * if you sort Files by Name, then images will automatically be sorted by name as well? This is because Image extends the File class. Is this also true for folders?

    * put your database config in the _ss_environment.php file.

    Hope that helps


    Posted by nicolaas, 16/06/2013 11:24pm (10 months ago)