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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

RESOLVED: Model Admin Associating Image


Reply


2 Posts   369 Views

Avatar
MattL

Community Member, 2 Posts

9 October 2012 at 11:55pm

I'm hoping someone is going to be able to shed some light on an issue I'm having with ModelAdmin. I using ModelAdmin to manage data associated with a jquery carousel.

Here is what I have:

Data Object

<?php
class CarouselItem extends DataObject {
   
   
   static $db = array(
      'Caption' => 'Text',
      'URL' => 'Varchar(255)'
   );
   
   static $has_one = array(
      'Photo' => 'Image'      
   );
   
   static $summary_fields = array(
      'URL',
      'Created',
      'LastEdited'
   );
   
}

?>

ModelAdmin code

<?php
class CarouselAdmin extends ModelAdmin
{

public static $managed_models = array(
'CarouselItem'
);

static $url_segment = 'carousel';
static $menu_title = 'Carousel Data';
   
}

?>

The above seems to work ok when it comes to saving the CarouselItem apart from the relationship to the image. The $has_one seems to create a PhotoID field on the CarouselItem table however this is the only field that is not updated when managing this data. Also I get a quick fade in message when attempting to select an image - the message that fades in is "Forbidden".

Am I missing something here ?

Any assistance would be greatly appreciated.

Avatar
MattL

Community Member, 2 Posts

10 October 2012 at 11:06pm

I discovered there was actually nothing wrong with the code. It's was simply a matter of saving the new record before adding the image to it. I guess SS had a hard time trying to associate the image to a record that didn't exist yet.