Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Adding an Images Tab in the backend

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: 893 Views
  • barrycorrigan
    Avatar
    Community Member
    10 Posts

    Adding an Images Tab in the backend Link to this post

    Hi Everyone,

    Having a bit of a problem that I hope someone could help me out with. Im trying to add an images tab in the backend. So the page is called PartnersPage.php and here is what i've added:

    <?php

    class PartnersPage extends Page {
    static $db = array(
          'Heading' => 'Text',
          'SubHeading' => 'Text',
          'WebLink' => 'Text'
    );
    static $has_one = array(
       'TopPhoto' => 'Image'

    );

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

    $fields->addFieldToTab('Root.Content.Main', new TextField('Heading'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('SubHeading'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('WebLink'), 'Content');
          
          $fields->addFieldToTab("Root.Content.Images", new ImageField('TopPhoto'));

    return $fields;
    }
    }

    class PartnersPage_Controller extends Page_Controller {

    }

    But as soon as I add the Image Field the website goes down and says

    "Sorry, there was a problem with handling your request.
    Visit www.silverstripe.org to download the CMS"

    Is this a common problem is there a simple fix for it?

  • JMagnusson
    Avatar
    Community Member
    29 Posts

    Re: Adding an Images Tab in the backend Link to this post

    I have the same problem. Have you find an answere?

    My code:
    <?php
    /**
    * Defines the SideBarPage page type
    */

    class SideBarPage extends Page {
       
       static $icon = "images/treeicons/sidebar";
       
       static $db = array(
    );

    static $has_one = array(
    'Photo1' => 'Image',
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
       
        $fields->removeByName('RightSide');
        $fields->removeByName('BannerImage');
        $fields->removefieldFromTab("Root.Content.Main","Content");
        $fields->removefieldFromTab("Root.Content.Main","SideBarPage");
       
        $fields->addFieldToTab( 'Root.Content.Images', new ImageField('Photo1') );

        return $fields;
    }

    static $defaults = array(
        'ShowInMenus' => false ,
        'ShowInSearch' => false
    );
    }

    class SideBarPage_Controller extends Page_Controller {

    }
    ?>

    And the result: "Sorry, there was a problem with handling your request."

    /Johan

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