Jump to:

23367 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » Manipulating the member table

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

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

Page: 1 2 3
Go to End
Author Topic: 2242 Views
  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Manipulating the member table Link to this post

    At this point I'm going to need to see all the code to figure out what is going on. Can you zip up all the relevant files and attach?

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Manipulating the member table Link to this post

    Cool, thanks for the reply.

    Files are attached, let me know if there is anything more you need.

    Much appreciated

    Attached Files
  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Manipulating the member table Link to this post

    Does something like this in your onBeforeWrite() call work?

       $group = new Group();

       $group->Code = 'CMSMain';

       $group->Title = $this->Title;

       $group->write();

       Permission::grant($group->ID, "CMSMain");

       $member = new Member();

       $member->FirstName = 'FirstName';

       $member->Surname = 'Surname';

       $member->Nickname = 'Nickname';

       $member->Email = 'Email';

       $member->Password = 'Password';

       $member->write();
       
       $member->Groups()->add($group);

       $member->write();
       $group->write();

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Manipulating the member table Link to this post

    Hi Dale,

    Yeah the security group is being created, the only bit I'm having trouble with is asigning a member to a group. The members are created as new members in the member table, they just need to belong to a security group now.

    Thanks

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Manipulating the member table Link to this post

    Well those accessors should be adding the. The one above has worked just fine for me on several projects.

    $member->Groups()->add($group);

    Or from the other end:

    $group->Members()->add($member);

    These do not work for you?

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Manipulating the member table Link to this post

    Hi Dale,

    Thanks for getting back, and if my replies seem far apart apologies, my laptop is in the shop getting fixed so I've not had the usual daily access to the internet.

    To answer the question, basically I have tried both of those accessors but to no avail. There must be something i am doing wrong, maybe its something stupid like a syntax error but I just can't see it.

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Manipulating the member table Link to this post

    That is very weird indeed. If your site is in Dev mode it should throw an error if those accessors aren't syntactically correct. I only have 2 more tricks up my sleeve;

    1. Try running $member->Groups()->removeAll(); before you do the ->add($group);
    2. Drop your Member table and /dev/build again. You'll loose your data but if it is a weird column or something getting it the way....start from scratch.

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: Manipulating the member table Link to this post

    Hi Dale,

    Thanks I'll try that and see if it works. So you think the code looks fine otherwise? And that would normally be the way to do something like this? I was worried that I had gone about things the wrong way, you know how you start to doubt yourself when things don't work?

    Ok anyway I'll let you know the outcome

    Cheers

    2242 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.