Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » RESOLVED: Model Admin Associating Image

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

Page: 1
Go to End
Author Topic: 323 Views
  • MattL
    Avatar
    Community Member
    2 Posts

    RESOLVED: Model Admin Associating Image Link to this post

    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.

  • MattL
    Avatar
    Community Member
    2 Posts

    Re: RESOLVED: Model Admin Associating Image Link to this post

    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.

    323 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.