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 /

SS3 - canCreate/canDelete functions


Reply


3 Posts   837 Views

Avatar
RuthAdele

Community Member, 19 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
simon_w

Forum Moderator, 474 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, 19 Posts

24 September 2012 at 6:36pm

Ah, thankyou very much! :)