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

Adding extension error


Go to End


7 Posts   1214 Views

Avatar
folibis

Community Member, 13 Posts

1 June 2013 at 10:38pm

Edited: 01/06/2013 10:40pm

I am trying to add new field to user profile, or rather image for avatar
I created new simple file

class MemberExtension extends DataExtension {
	static $db = array(
        'Avatar' => 'Varchar(200)',
    );

	function updateCMSFields(FieldList $fields) {
		$fields->addFieldToTab("Root.Main", new UploadField('Avatar'));
	}
}

and, of course
Object::add_extension("Member", "MemberExtension"); 

into _config.php
After that my CMS just got crazy.
I cant enter to Files or any else section. I cant upload image (got some Json error).
What i do wrong?

Avatar
Devlin

Community Member, 344 Posts

1 June 2013 at 10:44pm

UploadField expects a has_one relationship to the image class.

@see
http://doc.silverstripe.org/framework/en/reference/uploadfield

Avatar
folibis

Community Member, 13 Posts

2 June 2013 at 1:25am

class MemberExtension extends DataExtension {
	static $db = array(
        'Avatar' => 'Varchar(200)',
    );
	static $has_one = array(
        'AvatarImage' => 'Avatar'
    );
	function updateCMSFields(FieldList $fields) {
		$fields->addFieldToTab("Root.Main", new UploadField($name = 'AvatarImage',$title = 'Avatar image'));
	}
}

$has_one not helps.
And by the way there are no php errors in the log.
Any ideas?

Avatar
Devlin

Community Member, 344 Posts

2 June 2013 at 3:49am

As I've said, you need a relationship to a image class.

class MemberExtension extends DataExtension {
	static $has_one = array(
		'Avatar' => 'Image',
	);
	function updateCMSFields(FieldList $fields) {
		$fields->addFieldToTab("Root.Main", new UploadField('Avatar'));
	}
}

@see
http://doc.silverstripe.org/framework/en/reference/uploadfield

there are no php errors in the log

You need to set your enviroment to 'dev mode' for proper error messages.
Director::set_environment_type("dev");

@see
http://doc.silverstripe.org/framework/en/topics/debugging

Avatar
folibis

Community Member, 13 Posts

2 June 2013 at 8:31am

it was to no purpose
I have Director::set_environment_type("dev"); in my _config.php

After login to CMS it jumps to Page section. If I press "Files" or eny else section, loader appears for a seccond and nothing happened.
Button remains pressed.

Avatar
Devlin

Community Member, 344 Posts

2 June 2013 at 9:52am

I'm sure there is something in your error log. Did you rebuild your database? What version of Silverstripe do you use?

Avatar
folibis

Community Member, 13 Posts

2 June 2013 at 10:26am

Edited: 02/06/2013 10:27am

I use 3.0.55
And yes, i did /dev/build and /dev/build?flush=all too
my log is empty or, rather, there are no today records