Jump to:

5450 Posts in 1672 Topics by 1197 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: 623 Views
  • Rishi
    Avatar
    Community Member
    97 Posts

    trying to upload images on pages Link to this post

    Hello
    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

    ImageAttachment.php
    <?php

    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;
    }
    }

    ?>

    ProjectPage.php

    <?php
    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');

    $fields->removeFieldFromTab("Root.Content.Main","Content");

    $imagetable = new ComplexTableField(
    $this,
    '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;
    }
    }

    ?>

    ProjectPage.ss:

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

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

    623 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.