5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1312 Views |
-
page limit

6 August 2009 at 10:09pm
Please help me .. i am new user for silverstripe .
i want limit a page upto 10 pages .. after that when user try to create new page it should trough a error message that "Access Denied"
-
Re: page limit

9 August 2009 at 11:50am
You can create a function called canCreate() which has the permission if a user can create a given page. If you want this check to be over the whole site you would do something like this on your Page.php file in the Page class
function canCreate() {
$pages = DataObject::get('SiteTree');
return ($pages && $pages->Count() > 10) ? false : true;
} -
Re: page limit

10 August 2009 at 7:26am
Hi Will!
Maybe I'm wrong, but I think that it's worth mentioning that by creating this function we will overload (right term?) the canCreate() function present in DataObject. Isn't it?
Best regards,
Juan -
Re: page limit

10 August 2009 at 8:21am Last edited: 10 August 2009 8:23am
Yes, doing so, you will indeed overload the canCreate method (not of DataObject, but of SiteTree). But that isn't really a problem.
If you do user-permission checks in the canCreate method of a base-class, you can catch this first:function canCreate($member = null) {
// check permission of base-class
$permission = parent::canCreate($member);
// if there is no permission, we don't grant it here either.
if($permission === false)
return false;$pages = DataObject::get('SiteTree');
return ($pages && $pages->Count() > 10) ? false : true;
}That way, you can create up to 10 SiteTree instances, but only if you have the permissions to do so
-
Re: page limit

10 August 2009 at 4:40pm
thank for reply ..
but show me how to do in before tiger i want call that function in addpage() function ? CMSMain.phpit should send error message and i want display that message in CMSLeft.ss
please help me ....
-
Re: page limit

27 August 2009 at 9:37pm
following on from this, how would I only limit the number of Level1 (top-level) pages that can be created without placing a limit on Level2 pages?
-
Re: page limit

27 August 2009 at 11:31pm Last edited: 27 August 2009 11:35pm
Hi. That should be simple to implement. Use the canCreate method, listed above, but change the following:
$pages = DataObject::get('SiteTree', 'ParentID = 0');
The WHERE statement checks if ParentID is zero, which is only the case for top-level pages.
Update: Sorry, my solution is slightly flawed. The limit check will only occur on Level 1 Pages, but you won't be able to create sub-pages once that limit is reached. Sadly, I don't know an easy work-around for your problem, you would have to find out what level the currently selected item of the SiteTree Navigation belongs to. Maybe somebody knows a easy way to check this?
| 1312 Views | ||
|
Page:
1
|
Go to Top |




