Snippets - Little bits of code to make you happy
A _config.php Cheatsheet
Tweet2 July 2010 | | | Supports v2.4
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('me@mydomain.com'), 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('me@mydomain.com'); // //Set to CC all emails to Email::cc_all_emails_to('me@mydomain.com'); // /********************** * * 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);
16 Comments
RSS feed for comments on this page RSS feed for all comments
Pali
04/10/2010 9:40am (1 year ago)
hello, nice one ;)
should add this:
// v2.4
MySQLDatabase::set_connection_charset('utf8');
Patrick
11/10/2010 10:41am (1 year ago)
Nice Cheatsheet.
Line 87 LeftAndMain::remove_menu_item('Reports'); should be CMSMenu::remove_menu_item('CommentAdmin');"
Aram Balakjian
24/11/2010 1:16pm (1 year ago)
Thanks Patrick, amended
_Vince
18/12/2010 10:14pm (1 year ago)
Great post! But are you sure it's
i18n::set_locale('en_UK');
?
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 (1 year ago)
FYI...
if (Director::isDev()) {
SSViewer::flush_template_cache();
}
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 (1 year 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 (1 year 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 (1 year 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 comments....it's on the list ;)
swaiba
16/01/2011 1:34pm (1 year ago)
oh this reminds me... these were the items I'd previously suggested to go on here also...
1)
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']['LeftAndMain.ss']['SSWEB'] = 'Company Name';
$lang['en_US']['LeftAndMain.ss']['SSWEB'] = 'Company Name';
2)
Removing the help, this relates to teh above as clicking on help with show silverstripe also...
Object::add_extension('LeftAndMain', 'MyLeftAndMainDecorator');
MyLeftAndMainDecorator.php
<?php
class MyLeftAndMainDecorator extends LeftAndMainDecorator {
function init() {
CMSMenu::remove_menu_item('Help');
}
}
Also whats up with teh <br> tag at the start before the <?php ?
moloko_man
22/02/2011 6:19pm (12 months 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.
https://img.skitch.com/20110222-j4d8rqcf6pueywtxu41b6gx555.jpg
Oh and it happens on both my local dev server and my remote server.
moloko_man
22/02/2011 6:41pm (12 months 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 - http://my.site.com/my-media-room/"
thomas
07/03/2011 5:32pm (11 months ago)
Hello
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
/tmp/siverstripe-cache-var-www-vhost-yoururl
Hope it helps
Simon Erkelens
26/03/2011 11:36pm (11 months 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
* http://doc.silverstripe.org/doku.php?id=configuration
* for a description of what dev mode does.
* Remember, you can /dev/build on dev-servers without login!
*/
Director::set_dev_servers(array(
'localhost',
'127.0.0.1',
'yourdevlocation.website.com',
'more.website.com',
));
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 (4 months ago)
Hello,
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')->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');
//
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 (4 months ago)
Hey,
It worked!!
Might be because of cookies, it was not showing up!
Thanks a lot :)
theAlien
23/10/2011 10:37am (3 months ago)
Hi,
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");
Post a comment ...
You cannot post comments until you have logged in. Login Here.