Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Many images

Our old forums are still available as a read-only archive.

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

Page: 1 2 3
Go to End
Author Topic: 9265 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Many images Link to this post

    YOU ARE THE KING.

    Thanks you SO much!

    Now how about iterating through these in the template?? Is that possible? Seems that I'll need some sort of function which puts the images in a collection of some kind, as these images are not "Children" of the page in the classic sense.

    How would you go about that?

    Thanks in advance,
    Garrett

  • UncleCheese
    Avatar
    4085 Posts

    Re: Many images Link to this post

    <% control PropertyName %>

    will iterate through any has_many property of your object.

    on ProjectPage.ss:

    <% control ImageAttachments %>
    $Image
    $Title
    <% end_control %>

    I think I mentioned this before, but you probably want to check out the GD functions for your Images..

    http://doc.silverstripe.com/doku.php?id=imageupload

    Very useful, and I think one of the most powerful features of Silverstripe. Glad that all worked out for you.

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Many images Link to this post

    YES! I suppose that was the whole point of the ImageAttachment class, now, wasn't it ;) You have been a treMENdous help, I cannot thank you enough! My Image Gallery is totally rocking now.

    //Garrett

  • Rahul
    Avatar
    Community Member
    8 Posts

    Re: Many images Link to this post

    Hi,
    Please help me ...
    I am trying to upload multiple images for Product.
    while trying to save & publish page through admin i am facing this error ...

    ERROR:Error 256: Object::__call() Method 'ImageAttachment' not found in class 'Products' At l199 in D:\workspace\projects\silver\sapphire\core\Object.php

    Please find the code below ...
    Products.php file

    class Products extends Page {
          static $db = array(   
          'Industry' => 'Text',
          'Type' => 'Text',
          'Serving' => 'Text',   
          'Info' => 'Text',
          'ReviewsBuzz' => 'Text',
          'Technology' => 'Text',
          'WhatsCooking' => 'Text'      
          );
          
          static $has_one = array(   
           'TitleImage' => 'Image',
        'ThumbnailImage' => 'Image'
        );
          static $has_Many = array(
             'ImageAttachment' => 'ImageAttachment'
          );
        function getCMSFields() {
           $fields = parent::getCMSFields();
          
           $fields->addFieldToTab('Root.Content.Main', new ImageField('TitleImage', 'Title Image'));          
           $fields->addFieldToTab('Root.Content.Main', new TextField('Industry','Industry'));
           $fields->addFieldToTab('Root.Content.Main', new TextField('Type','Type'));
           $fields->addFieldToTab('Root.Content.Main', new TextField('Serving','Serving'));
           $fields->addFieldToTab('Root.Content.Main', new TextareaField('Info','Info'));
           $fields->addFieldToTab('Root.Content.Main', new TextareaField('ReviewsBuzz','Reviews Buzz'));
           $fields->addFieldToTab('Root.Content.Main', new TextareaField('Technology','Technology'));
           $fields->addFieldToTab('Root.Content.Main', new TextareaField('WhatsCooking','Whats Cooking'));
           $fields->addFieldToTab('Root.Content.Main', new ImageField('ThumbnailImage', 'Screen Shot'));
          
           $fields->removeFieldFromTab("Root.Content.Main","Content");
          
           $imagetable = new HasManyComplexTableField(
                $this,
                'ImageAttachment', // relation name
                'ImageAttachment', // object class
                /*array(
                 'Link' => 'Link',
                 'ImageID' => 'Image'            
           ),
           'getCMSFields_forPopup'*/
                ImageAttachment::$field_names, // fields to show in table
                ImageAttachment::getCMSFields_forPopup(), // form that pops up for edit
                "ProductsID = {$this->ID}" // a filter to only display item associated with this page          
             );
                //$imagetable->setParentClass('Products');
                //$imagetable->setAddTitle( 'A Image' );
                
                $fields->addFieldToTab('Root.Content.RightPanelImage', $imagetable);
                
           return $fields;
          }
       }
       
       class Products_Controller extends Page_Controller{
       
          
          
          
       }

    ImageAttachment.php File

    class ImageAttachment extends DataObject {
       static $db = array(
       'Link' => 'Text'
       );
       static $has_one = array(   
       'Image' => 'Image',
       'Products' => 'Products'
       );
       
       static $field_names = array('Link' => 'Link');
       
       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push(new TextField('Link', 'Link'));      
          $fields->push(new ImageField('Image', 'Image'));
          
          return $fields;
       }
    }

    Please tell me what i am doing wrong.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Many images Link to this post

    typo...

    $has_Many should be $has_many

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: Many images Link to this post

    I'd be happy to help you if you would remove the strikethroughs from your code so I can read it.

    Thanks,
    Garrett

  • Rahul
    Avatar
    Community Member
    8 Posts

    Re: Many images Link to this post

    Hi UncleCheese
    It Worked .... Thanks

    Sorry Garrett .... by mistake i done strikethroughs ...

    9265 Views
Page: 1 2 3
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.