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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Prevent page from having any children.


Go to End


5 Posts   1595 Views

Avatar
AnimalStripe

Community Member, 14 Posts

18 March 2015 at 11:50pm

I have a page type that I don't want further pages added to. I've tried:

private static $allowed_children = array ();

and

private static $allowed_children = array (NULL);

but the CMS still allows me to add children. How do I go about ensuring that the page is an end note in the tree?

Avatar
wmk

Community Member, 87 Posts

19 March 2015 at 12:06am

From looking at source just set $allowed_children to string "none" and flush. You could also overwrite the allowedChildren() method...

hth, wmk

Avatar
AnimalStripe

Community Member, 14 Posts

19 March 2015 at 12:12am

Duh! Didn't flush!

Thanks.

Avatar
GioVdK

Community Member, 1 Post

19 March 2015 at 12:27am

Edited: 19/03/2015 12:28am

Hi,
the way I usually do it is with

private static $allowed_children = false;

as for me it makes more sense to be an empty value (false or empty array) rather than the string 'none', but I saw that (as suggested by wmk) the docs are suggesting the use of 'none':

"This can be an array of allowed child classes, or the string "none" indicating that this page type can't have children."

Avatar
wmk

Community Member, 87 Posts

19 March 2015 at 12:35am

@GioVdK you're totally right. false and any falsy element (including empty array) should be possible and seems much cleaner. Maybe the inline docs are a bit old...?