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.

Data Model Questions /

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

Permissions and canCreate()


Go to End


2 Posts   1631 Views

Avatar
neros3

Community Member, 51 Posts

23 June 2010 at 12:58am

Hi

I have a class that extends Page.
I have implemented the canCreate($member = null) function on it.
On another page that holds a custom form to create a new page I was hoping that the canCreate function was called on write or perhaps on the instantiation (new). But the function is never called.

Is the canCreate not called automatically? Perhaps not working on Page? I'm confused.

MyPage.php

 
class MyPage extends Page {
   static $db = array(
   );
   static $has_one = array(
   );

    public function canCreate($member = null){

        echo "<h1>lala</h1>";
        return false;

    }
}

MyForm.php

 

    public function canCreate($member = null){

        $mypage = new MyPage();
        $mypage->Title = "my page";
        $mypage->write(); // I would expect something to happen here, but the page is just created like any other page.

    }

Avatar
neros3

Community Member, 51 Posts

23 June 2010 at 2:33am

Hi folks
So far I've come to the conclusion that the canCreate function is only automatically called from the CMS. Anyone wants to support this statement?
Thanks!