0

I'm currently working on an image slider for the home page of the site I'm working on, and I've had no problems setting up the many_many relationship and UploadField in the CMS. My problem is that I want to have a clickthrough link for each image in the carousel.

How should I represent this in my model, and is there any quick and painless solution that I can use to seamlessly allow the user to associate a URL with the image they just uploaded.

Here's my code thus far:

class HomePage extends Page {

    private static $many_many = array(
                'Images'    => 'Image'
        );

    public function getCMSFields ()
    {
        $fields = parent::getCMSFields();

        $upload = new UploadField('Images', 'Slider Images (JPG or PNG)', $this->Images()); // Create a new upload field and set its name to 'Logo'.
        $upload->setAllowedExtensions( array( 'JPG', 'PNG' ) );
        $upload->setConfig('allowedMaxFileNumber', 5); // Allow 5 files for this field

        return $fields;
    }
}
Martin T.
  • 445
  • 1
  • 7
  • 18
  • 4
    Have a look at this question and answer: https://stackoverflow.com/questions/14432739/silverstripe-uploadify-add-fields/14432868 – 3dgoo Feb 27 '14 at 21:18
  • 2
    3dgoo's excellent answer in the comment above is exactly what you're after. To summarise, what you want to do is create a DataObject (ie Slide) with Image and URL fields. And your HomePage has a has_many relationship with SlideObject. – Prembo Feb 28 '14 at 21:37

0 Answers0