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

new member(); , Making new members from PHP


Go to End


7 Posts   1241 Views

Avatar
DesignerX.com.au

Community Member, 107 Posts

29 April 2012 at 3:00am

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 ?

Avatar
Willr

Forum Moderator, 5523 Posts

29 April 2012 at 11:07am

Edited: 29/04/2012 11:07am

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?

Avatar
DesignerX.com.au

Community Member, 107 Posts

29 April 2012 at 2:24pm

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 !

Avatar
Willr

Forum Moderator, 5523 Posts

29 April 2012 at 2:33pm

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.

Avatar
DesignerX.com.au

Community Member, 107 Posts

29 April 2012 at 3:33pm

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{

}

Avatar
Willr

Forum Moderator, 5523 Posts

29 April 2012 at 3:50pm

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

Avatar
DesignerX.com.au

Community Member, 107 Posts

29 April 2012 at 4:58pm

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