SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

A _config.php Cheatsheet


If your anything like me, you've probably found yourself going through your previous sites looking for that line of code to put in your _config.php file. Well, now you nolonger need to, simply bookmark this page and return to it any time you need to add a line to your config! And if I've missed out anything leave a comment and I'll make sure it gets added :)

<?php /********************** * * Errors / Dev * **********************/ // //Force enviroment to Dev ** REMOVE FOR LIVE SITES ** Director::set_environment_type("dev"); // //Force cache to flush on page load if in Dev mode (prevents needing ?flush=1 on the end of a URL) if (Director::isDev()) { SSViewer::flush_template_cache(); } //(v2.4) Log errors to an email address SS_Log::add_writer(new SS_LogEmailWriter(''), SS_Log::ERR); // //(v2.4) Log errors to a file SS_Log::add_writer(new SS_LogFileWriter('error_log.txt'), SS_Log::ERR); // /********************** * * CMS Rebranding * **********************/ // //Set the CMS application name, logo and loading image LeftAndMain::setApplicationName("My application"); LeftAndMain::setLogo("themes/MyTheme/images/CMSLogo.png", "margin-top: -3px;"); LeftAndMain::set_loading_image('themes/MyTheme/images/CMSLoading.gif'); // /********************** * * Security * **********************/ // //Set default login Security::setDefaultAdmin('admin','pass'); // //Define the password validator $pwdValidator = new PasswordValidator(); $pwdValidator->minLength(8); $pwdValidator->checkHistoricalPasswords(2); $pwdValidator->characterStrength(2,array('lowercase','digits')); Member::set_password_validator($pwdValidator); // // Set the site locale i18n::set_locale('en_UK'); // /********************** * * Templates / ULRs * **********************/ // //Remove Prototype / Behaviour validation and use your own Validator::set_javascript_validation_handler('none'); // // Set the theme SSViewer::set_theme('FBO'); //Enable Search, use $SearchForm in template FulltextSearchable::enable(); // //Turn off # link rewriting SSViewer::setOption('rewriteHashlinks', false); // //Force redirect to www. Director::forceWWW(); // //(v2.4) enable nested URLs for this site (e.g. page/sub-page/) SiteTree::enable_nested_urls(); // // Set the Breadcrumb divider SiteTree::$breadcrumbs_delimiter = " >> "; // // Set the resizing image quality GD::set_default_quality(95); // /********************** * * CMS UI * **********************/ // //Hide a main CMS Tab CMSMenu::remove_menu_item('CommentAdmin'); // //Make a data objects sortable (for DOM) SortableDataObject::add_sortable_classes(array( 'DataObject', 'AnotherDataObject' )); // //Set HTML EDitor Config HtmlEditorConfig::get('cms')->setOption('convert_fonts_to_spans', false); // HtmlEditorConfig::get('cms')->enablePlugins('searchreplace'); // HtmlEditorConfig::get('cms')->insertButtonsAfter('pasteword', 'replace'); // HtmlEditorConfig::get('cms')->setOptions(array( 'content_css' => 'static/css/editor.css' )); // //Add requirments to the CMS LeftAndMain::require_javascript('mysite/javascript/jquery.cms.js'); // LeftAndMain::require_css('themes/mytheme/css/cms.css'); // /********************** * * Classes / Objects * **********************/ // //Add an extention to an object and DataObject Object::add_extension('SiteConfig', 'CustomSiteConfig'); DataObject::add_extension('DataObject', 'DataObjectExtension'); // // Use a custom class instead of a core one Object::useCustomClass('MemberLoginForm', 'CustomLoginForm'); // //Set allowed file types File::$allowed_extensions[] = "f4v"; // /********************** * * Emails * **********************/ // //Set the admin email address Email::setAdminEmail(''); // //Set to CC all emails to Email::cc_all_emails_to(''); // /********************** * * Comments * **********************/ // //Enable comment spam protection MathSpamProtection::setEnabled(); // //Enable comment moderation PageComment::enableModeration(); // //Force user to be logged in to post a comment PageCommentInterface::set_comments_require_login(true);
Aram Balakjian avatar

Aram Balakjian

Aram is a web developer running London based agency Aab Web. He has a strong passion for developing attractive, usable sites around the SilverStripe CMS.

  • Pali
    04/10/2010 9:40am (7 years ago)

    hello, nice one ;)

    should add this:
    // v2.4

  • Patrick
    11/10/2010 10:41am (7 years ago)

    Nice Cheatsheet.

    Line 87 LeftAndMain::remove_menu_item('Reports'); should be CMSMenu::remove_menu_item('CommentAdmin');"

  • Aram Balakjian
    24/11/2010 1:16pm (7 years ago)

    Thanks Patrick, amended

  • _Vince
    18/12/2010 10:14pm (7 years ago)

    Great post! But are you sure it's



    I tried that and the page containing a calendar field wouldn't display until I set it back to en_GB.

  • swaiba
    07/01/2011 12:40pm (6 years ago)

    if (Director::isDev()) {
    Caused random cache error over and over for me (only in dev mode) so I haad to stop using it - instead I create a silverstripe-cache and delete that to force a complete rebuild - which is normally for nested templates - even a deb/build flush all does not update these...

  • Aram Balakjian
    07/01/2011 12:52pm (6 years ago)

    Hi Swaiba, what was the error you were receiving, and which version of SS? I have never had any problems, but then I don't think I have used it on the most recent versions.

  • swaiba
    14/01/2011 9:03am (6 years ago)

    2.4.x - the only thing I can think of is that the nesting of includes at a place on the site is causing it (as I said I still needed to create silverstripe-cache to be able to really delete the cache). Sorry for my late response - I wasn't notified of your reply - also is it possible to edit posts? I can see tons of typos in my post above!

  • Aram Balakjian
    14/01/2011 9:32am (6 years ago)

    hmm, that is strange, I will leave it in there for now but if anyone else comes accross issues please let me know.

    Unfortunately I havent got around to creating a way to edit's on the list ;)

  • swaiba
    16/01/2011 1:34pm (6 years ago)

    oh this reminds me... these were the items I'd previously suggested to go on here also...

    Complete the rebranding even if you rebrand the tooltip of the CMS link in the bottom right still says silverstripe, but this removes it...
    global $lang;
    $lang['en_GB']['']['SSWEB'] = 'Company Name';
    $lang['en_US']['']['SSWEB'] = 'Company Name';

    Removing the help, this relates to teh above as clicking on help with show silverstripe also...
    Object::add_extension('LeftAndMain', 'MyLeftAndMainDecorator');

    class MyLeftAndMainDecorator extends LeftAndMainDecorator {
    function init() {

    Also whats up with teh <br> tag at the start before the <?php ?

  • moloko_man
    22/02/2011 6:19pm (6 years ago)

    I am also getting the same cache error as swaiba. Its random, I get it maybe once every 20 reloads while another developer may get it once every 10 reloads.

    Here is a screenshot of the error.

    Oh and it happens on both my local dev server and my remote server.

  • moloko_man
    22/02/2011 6:41pm (6 years ago)

    Just got the same error again, this time I had firebug open and it reported a Network Error: "NetworkError: 500 Warning: "include(/...phire/core/SSViewer.php -"

  • thomas
    07/03/2011 5:32pm (6 years ago)


    I had the same error and finaly got trough:

    In order to have this working you have to set authorisations to 777 to the folder that contain temp files for the ss website on my linux/debian it is

    Hope it helps

  • Simon Erkelens
    26/03/2011 11:36pm (6 years ago)

    In stead of defining dev the hardcoded way, this is a better way to do it:

    * Sites running on the following servers will be
    * run in development mode. See
    * for a description of what dev mode does.
    * Remember, you can /dev/build on dev-servers without login!
    Every given url gives automatically a dev-mode. saves a lot of hassle with unsetting.

    Also, this feature can be linked to database settings, if-in-dev, use different db-settings. (For safety, still, please, do delete your dev-settings after live still ;) )

  • ypmhp
    26/09/2011 10:53pm (6 years ago)


    I just added these codes to prevent HTML CODE STRIPPING::

    //Set HTML EDitor Config
    HtmlEditorConfig::get('cms')->setOption('convert_fonts_to_spans', false);
    HtmlEditorConfig::get('cms')->insertButtonsAfter('pasteword', 'replace');
    HtmlEditorConfig::get('cms')->setOptions(array( 'content_css' => 'static/css/editor.css' ));
    //Add requirments to the CMS

    But still the BIDVERTISER ad code, I am inserting in HTML Editor dont work and I cannot see the banner.

    Is there something I am missing?

    Plz revert back...

  • ypmhp
    27/09/2011 9:37am (6 years ago)


    It worked!!

    Might be because of cookies, it was not showing up!
    Thanks a lot :)

  • theAlien
    23/10/2011 10:37am (6 years ago)


    Line 28: LeftAndMain::setApplicationName("My application"); is more complete if you changed it to:

    LeftAndMain::setApplicationName($name = "Application text at the bottom",$logoText = "Text next to logo",$link = "Link to website");

  • plop
    07/03/2012 3:23pm (5 years ago)

    Hi Aram,

    First of all, thanks you for share your work :) it's really appreciated

    So that is my story ^^ i'm new on SS and I have just started to work with it
    My first project is to manage Member on my website, so I use Memberprofiles Module But there are few things I don't understand and I hope you can help me :)

    I want to configure the password like this :
    - At least 6 Caracters
    - Password different from Login
    - At least 1 number and 1 letter

    But when i put your code in my _config.php after Dev/build/?flush=1
    nothing appends :(

    that is all for the moment ^^

    Thanks for answering me :)

    Best regards

  • Aram Balakjian
    07/03/2012 3:25pm (5 years ago)

    Hi Plop,

    Password validation doesn't change anything in the database, it will come into effect when you try to define a password.


  • plop
    07/03/2012 9:07pm (5 years ago)

    So How i have to do ?

    I put this code below in my _config.php :

    $pwdValidator = new PasswordValidator();

    But it works only on Chrome and not on Firefox xD
    i'm a little lost ^^

    if you have any ideas, i'm taking theses ^^


  • plop
    09/03/2012 2:50pm (5 years ago)

    I Take video of my tests with Chrome and Firefox for a better understanding :) I hope it will be help ^^

    The first test with Google Chrome, as you can see it's working

    The second with Firefox and now i can see that there are a sort of latency

    I hope you can help me :)



  • nicolaas
    12/12/2012 5:56am (5 years ago)

    What is the joy of having a <br> at the top of the _config.php file?

  • tazzydemon
    07/04/2013 2:01am (4 years ago)

    I think its about time we had a /_config/config.yml plus _config.php combo cheatsheet. what you put in either when upgrading from a pure SS3 _config.php is quite confusing and the docs are awful!!

  • dakiquang
    19/11/2014 2:36am (3 years ago)

    Hi all,

    I'm using SS 3.1. How can I change logo in LeftAndMain CMS ?

Post a comment ...

You cannot post comments until you have logged in. Login Here.


Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image wfacewomens
3 article image Daniel Hensby
4 article image Marcus Dalgren
5 article image ryduhartchas
6 article image Hamish Campbell
7 article image Ty Barho
8 article image Martijn van Nieuwenhoven
9 article image Darren-Lee
10 article image Roman Schmid

View full leaderboard