Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » new member(); , Making new members from PHP

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
Go to End
Author Topic: 816 Views
  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    new member(); , Making new members from PHP Link to this post

    hi,
    I need help making members from php. The idea was to create a function then use that function to make as many members as i need, here what i have done ( does not work ):
    <?php

    class AddMembers extends Member {

       public static $db = array(
       );

       public static $has_one = array(
       );
    function AddAMember ($name,$email,$pass){
    $member = new Member();
    $member ->FirstName = "$Name";
    $member ->Email = "$email";
    $member ->Password = "$password";
    $member ->write();
    return false;
    }
    AddAMember("NameHere","xxx@xx.xxx","PassHere");
    }

    What am i missing ?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: new member(); , Making new members from PHP Link to this post

    new Member() is correct, It looks like you have a Class AddMember which extends Member - that is slightly weird, if AddMembers() is just a helper function you don't need to extend member. Also, where are you trying to invoke the AddAMember function?

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: new member(); , Making new members from PHP Link to this post

    i need this to be able to run globally , so when ever i call $AddMembers in any page, the function will be invoked . Something like $Siteconfig !

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: new member(); , Making new members from PHP Link to this post

    Not really ideal to have global functions just floating around adding members but if that's want you want to do then like you said, could put it on SiteConfig!

    The template engine only supports 2 arguments anyway so you wouldn't be able to use the function in templates. If you need to use it in PHP anywhere then just make the function static.

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: new member(); , Making new members from PHP Link to this post

    The following code does not work ! I dont get where Its wrong!
    AddedMembers.ss:
    $AddedMembers.AddMemberA
    $AddedMembers.AddMemberB

    AddedMembers.php:
    <?php

    class AddedMembers extends Page {

    public static $db = array(
    );

    public static $has_one = array(
    "Member"=>"Member",
    );

    function AddAMemberA(){
    $member = new Member();
    $member ->FirstName = "aaa";
    $member ->Email = "123123@edrf.edf";
    $member ->Password = "aaaaa";
    $member ->write();
    //return $member;
    }

    function AddAMemberB(){
    $member = new Member();
    $member ->FirstName = "bbbbb";
    $member ->Email = "bbbb@bbb.edf";
    $member ->Password = "bbbbb";
    $member ->write();
    //return $member;
    }
    }

    Class AddedMembers_Controller extends Page_Controller{

    }

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: new member(); , Making new members from PHP Link to this post

    Because you just can't do $Class.SomeFunc. $SiteConfig works as there is a function SiteConfig which returns the site config class [1]

    You have to put that function on either your Page class (then it's accessible on every Page) or put it as an extension to SiteConfig and use $SiteConfig.AddMember.

    I would suggest putting those functions in your Page class (or at least having a wrapper)

    <?php

    class Page extends SiteTree {

    function AddMember() {
    // do stuff! either include the function in here or make the AddAMemberA() function Static and call it like AddedMembers::AddAMemberA()
    }

    [1] http://api.silverstripe.org/2.4/sapphire/control/ContentController.html#methodSiteConfig

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: new member(); , Making new members from PHP Link to this post

    thank you , This make more sense now ;)
    The reason I am doing this is because i Need to get something like Facebook connect working .
    I have opened a topic to try fix FacebookConnect but no one replied yet . http://www.silverstripe.org/general-questions/show/19776

    I ma trying to use the xample provied by facebook to get the visitor to login from my website & pull the data then use the php code above to add the member to the data bse. I know its not the best way, but the only way if i cant get FacebookConnect module working.

    If you have time, please have a look at the FacebookConnect module , I was told it only need some basic updates to mach the new facebook code ?

    Thank you

    816 Views
Page: 1
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.