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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

SS3 - canCreate/canDelete functions


Go to End


3 Posts   2136 Views

Avatar
RuthAdele

Community Member, 21 Posts

24 September 2012 at 5:36pm

Edited: 24/09/2012 5:37pm

Hi guys,

I like to stop pages from being created if there is already an instance of it, and likewise stop it from being deleted.
Up until I started using Silverstripe 3 (last week), I've been using the following code:

public function canCreate() {       
	return false
}
public function canDelete() {       
	return false
}

or

public function canCreate() {       
	return !DataObject::get_one($this->ClassName);
}
public function canDelete() {       
	return !DataObject::get_one($this->ClassName);
}

However now it doesn't work with SS3. I get the following error:
[Strict Notice] Declaration of HomePage::canCreate() should be compatible with that of SiteTree::canCreate()

Does anyone know how I can get the same functionality in SS3?

Thanks in advance,
Ruth.

Avatar
(deleted)

Community Member, 473 Posts

24 September 2012 at 6:32pm

That functionality still works, you just need to have method decelerations be compatible with those you're overriding. Usually, this just means have the same prototype.

In this case, that's

public function canCreate($member = null)
.

Avatar
RuthAdele

Community Member, 21 Posts

24 September 2012 at 6:36pm

Ah, thankyou very much! :)