5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1515 Views |
-
problem with Member::currentUser();

20 May 2009 at 3:33am
hi
i have SS 2.3.1
i want to do exactly the same as here http://www.silverstripe.org/archive/show/85210 but it doesnt work
maby set default TextField value by $defaults but how to put member FirstName into Autor field ?
public static $db = array(
"Autor" => 'Text'
);static $defaults = array(
"Autor" =>
); -
Re: problem with Member::currentUser();

20 May 2009 at 7:29pm
Hi snaip,
you can it relate to another class, which give an return-value as the FirstName. So you have to create a function, which send a request to the the database. I don't have enough time to write an example. I'm sure, that my solution would run.
Bets regards,
Pascal
-
Re: problem with Member::currentUser();

23 May 2009 at 9:16am Last edited: 23 May 2009 9:22am
hmm i tried this:
public static $db = array(
'Author' => 'Text'
);function getCMSFields() {
$fields = parent::getCMSFields();
$member = Member::currentUser();
$options = array(''.$member->FirsName.'');
$fields->addFieldToTab("Root.Content.Main", new DropdownField("Author", "Author:", $options), 'Content');
return $fields;
}but when i save i get "Javascript parse error" :/
and hmm why i cant set value to the TextField ?
this doesn't work, http://doc.silverstripe.com/doku.php?id=textfield :$fields->addFieldToTab("Root.Content.Main", new TextField('Author','Author:','Enter Your name'),'Content');
-
Re: problem with Member::currentUser();

23 May 2009 at 5:58pm
You need to overload populateDefaults() instead of setting the item in the array.
e.g.
/**
* Set up the defaults for this class.
*
* Overloaded from DataObject to support more complicated
* defaults, such as calling a function to get a dynamic value.
*
* @return array
*/
public function populateDefaults() {
parent::populateDefaults();
$memberName = Member::currentUser() ? Member::currentUser()->getName() : null;
$this->setField('Author', $memberName);
}
| 1515 Views | ||
|
Page:
1
|
Go to Top |



