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

Add value manually to many_many_extrafields


Go to End


3 Posts   3351 Views

Avatar
khanhdeux

Community Member, 13 Posts

20 December 2013 at 1:51am

Hi team,
I have a problem when editing the form (not gridfield at backend). I have
class Channel extends DataObject {

private static $db = array(
'ChannelTitle' => 'Varchar(255)',
'ChannelDescription' => 'Text'
);
private static $many_many = array(
'Videos' => 'Video'
);
private static $summary_fields = array(
'ChannelTitle'
);
private static $many_many_extraFields = array(
'Videos' => array(
'PublishedDate' => 'SS_Datetime',
'UnpublishedDate' => 'SS_Datetime'
)
);

}
And
class Video extends DataObject {

const IMAGE_MAX_FILE_SIZE = 1000000;
const VIDEO_MAX_FILE_SIZE = 500000000;

public static $image_extension = array('jpg', 'jpeg', 'gif', 'png');
public static $video_extension = array('mp4', 'ogg', 'avi', 'mov');
private static $db = array(
'VideoTitle' => 'Varchar(255)',
'VideoDescription' => 'Text'
);
private static $has_one = array(
'VideoImage' => 'Image',
'VideoFile' => 'File',
'Owner' => 'Member'
);
private static $has_many = array(
'Comments' => 'VideoComment'
);
private static $belongs_many_many = array(
'VideoCategories' => 'VideoCategory',
'Channels' => 'Channel',
);
);

Now i want to add value manually to table Channel_Videos for the doeditform. I tried with getManyManyComponent without being successful. Any help really appreciate

Avatar
kinglozzer

Community Member, 187 Posts

20 December 2013 at 4:33am

Hi khanhdeux,

Perhaps this will be of some help: http://api.silverstripe.org/3.1/class-ManyManyList.html#_add

For example:

$videos = $this->Videos();
$videos->add($myVideo, array('PublishedDate' => '12/12/2013 11:11:11));

Loz

Avatar
MarijnKampf

Community Member, 176 Posts

17 April 2015 at 12:31am

Note to self (as it took me quite a while to figure out how to do this/find this post and I know I'm going to foget before I need it again). Programmatically add extrafields to many_many relation from php code.