Jump to:

5554 Posts in 1742 Topics by 1227 members

Customising the CMS

SilverStripe Forums » Customising the CMS » trying to upload images on pages

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

Page: 1
Go to End
Author Topic: 663 Views
  • Rishi
    Community Member
    97 Posts

    trying to upload images on pages Link to this post

    i am trying to allow upload feature from admin panel on pages and display the images on the page,the code i have tried is giving me an error in admin panel and also dont no how to restrict the number of max upload images to 3 the code is


    class ImageAttachment extends DataObject {
    static $db = array(
    'Title' => 'Text'

    static $has_one = array(
    'Image' => 'Image',
    'ProjectPage' => 'ProjectPage'

    static $field_names = array(
    'Image' => 'Image',
    'Title' => 'Title'

    function getCMSFields_forPopup() {

    $fields = new FieldSet();

    $fields->push(new TextField('Title', 'Title'));
    $fields->push(new ImageField('Image', 'Image'));

    return $fields;



    class ProjectPage extends Page {

    static $db = array(
    'ProjectChallenge' => 'Text'
    ,'ProjectSolution' => 'Text'
    ,'ProjectResults' => 'Text'
    ,'ImageMainTitle' => 'Text'

    static $has_one = array(
    'ImageMain' => 'Image',
    'ThumbnailMain' => 'Image'

    static $has_many = array(
    'ImageAttachments' => 'ImageAttachment'

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

    $fields->addFieldToTab("Root.Content.Main", new TextAreaField('ProjectChallenge', 'The Challenge'), 'Content');
    $fields->addFieldToTab("Root.Content.Main", new TextAreaField('ProjectSolution', 'The Solution'), 'Content');
    $fields->addFieldToTab("Root.Content.Main", new TextAreaField('ProjectResults', 'The Results'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new ImageField('ImageMain', 'Main Image'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new ImageField('ThumbnailMain', 'Main Thumbnail'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('ImageMainTitle', 'Main Image Title'), 'Content');


    $imagetable = new ComplexTableField(
    'ImageAttachments', // relation name
    'ImageAttachment', // object class
    ImageAttachment::$field_names, // fields to show in table
    ImageAttachment::getCMSFields_forPopup(), // form that pops up for edit
    "ProjectPageID = {$this->ID}", // a filter to only display item associated with this page
    "Name ASC" // Sort by name
    $fields->addFieldToTab('Root.Content.ImageAttachments', $imagetable);

    return $fields;



    <% control ImageAttachments %>
    <% end_control %>

    when i am trying to create a page of page type Projectpage its giving be a error
    thank you in advance

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.