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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

problem with Member::currentUser();

Go to End

5 Posts   2613 Views


Community Member, 181 Posts

20 May 2009 at 3:33am


i have SS 2.3.1

i want to do exactly the same as here 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" => 


Community Member, 47 Posts

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,



Community Member, 181 Posts

23 May 2009 at 9:16am

Edited: 23/05/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, :

$fields->addFieldToTab("Root.Content.Main", new TextField('Author','Author:','Enter Your name'),'Content');


Forum Moderator, 922 Posts

23 May 2009 at 5:58pm

You need to overload populateDefaults() instead of setting the item in the array.


 * 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() {
	$memberName = Member::currentUser() ? Member::currentUser()->getName() : null;
	$this->setField('Author', $memberName);


Community Member, 181 Posts

23 May 2009 at 9:41pm

thanks a lot Sean :]