Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Extending core classes (like Security)

Go to End

9 Posts   5274 Views


Community Member, 78 Posts

31 March 2009 at 2:56am


I was wondering how I could extend core classes within SilverStripe.
For example I want to extend Security and overrule setDefaultAdmin() and check_default_admin() to allow a hashed password to be used instead of plain-text.
I could of course alter Security.php itself, but I don't want to lose my changes when updating to a newer version.

Any help would be much appreciated!



Community Member, 78 Posts

31 March 2009 at 6:47pm

The only solution I came up with so far is to copy Security.php to mysite/code/Security.php and make sure that get's loaded instead of the original one.
This is still gonna be a hassle upgrading though, but at least changes won't be overwritten this way.

To further expand my question, how expendable / customizable is SilverStripe.
- What can be changed besides modules and templates?
- What are no goes?
- etc etc


Ben Gribaudo

Community Member, 181 Posts

1 April 2009 at 2:32am

Hi Geert,

Have you tried Object::useCustomClass('OldClass','NewClass')? Not sure if it will work for replacing Security as it only works for some classes. More details:


Community Member, 78 Posts

1 April 2009 at 3:35am

Edited: 01/04/2009 3:36am

Hi Ben,

The problem there is that some functions are called statically (in particular the ones I want to overrule), so the class name should be the same.
Something like Object::useCustomClass('Security','Security'); is bound to fail.
So i think the problem still remains...
Thanks for your reply though.

Also my other question about the limits of customization still remains.



Community Member, 78 Posts

3 April 2009 at 9:17am

Sorry to bring this up again, but still looking for answers.
Thanks in advance


Community Member, 1 Post

3 April 2009 at 9:16pm

Just an idea: Read a little about SVN and use the SS repository to get the source code and modify it like you want. To get a new version, just update the repository, and it merges edited files automatically.


Community Member, 78 Posts

6 April 2009 at 7:24pm

The SVN option was already considered, but the preferred option would be to alter the CMS without actually modifying the source code.
With DataObject this can indeed be done perfectly, but as stated before this doesn't work that well on other classes.


Community Member, 150 Posts

14 February 2012 at 11:32pm

Edited: 14/02/2012 11:35pm

Although this is post is quite old, I'm having the same problem here. See below for the changes that I've hacked into Security.php (mostly it's commenting out the functionality for the tabs). Problem now is that I have to create for all my other websites too, and that's not the idea here.

O, and my actual requirement: how can I load Security_login in a 100% custom template WITHOUT all kinds of JS and CSS stuff being put in (which is currently done by Security.php).

PS. I have tried <% control LoginForm %> in Security_login, but than the error messages ("wrong email/pass") are not shown :(

//		// only display tabs when more than one authenticator is provided
//		// to save bandwidth and reduce the amount of custom styling needed 
//		if(count($forms) > 1) {
//			Requirements::javascript(SAPPHIRE_DIR . '/javascript/loader.js');
//			Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
//			Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
//			Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
//			Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/effects.js");
//			Requirements::css(SAPPHIRE_DIR . "/css/Form.css");
//			// Needed because the <base href=".."> in the template makes problems
//			// with the tabstrip library otherwise
//			$link_base = Director::absoluteURL($this->Link("login"));
//			Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
//			Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_improvements.js");
//			Requirements::javascript(THIRDPARTY_DIR . "/tabstrip/tabstrip.js");
//			Requirements::css(THIRDPARTY_DIR . "/tabstrip/tabstrip.css");
//			$content = '<div id="Form_EditForm">';
//			$content .= '<ul class="tabstrip">';
//			$content_forms = '';
//			foreach($forms as $form) {
//				$content .= "<li><a href=\"$link_base#{$form->FormName()}_tab\">{$form->getAuthenticator()->get_name()}</a></li>\n";
//				$content_forms .= '<div class="tab" id="' . $form->FormName() . '_tab">' . $form->forTemplate() . "</div>\n";
//			}
//			$content .= "</ul>\n" . $content_forms . "\n</div>\n";
//		} else {
//			$content .= $forms[0]->forTemplate();
//		}
		$content .= $forms[0]->renderWith('CustomLoginForm');

Go to Top