Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » ImageField stays blank

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

Page: 1
Go to End
Author Topic: 1877 Views
  • CDGIDev
    Avatar
    Community Member
    9 Posts

    ImageField stays blank Link to this post

    I'd like to setup an image field for my users in a custom built page... Code pasted below after post...

    When i rebuild and then launch the CMS anew and go to the page. I see all 3 new fields, placed correclty but both imagefields just stay gray! Am i missing something?

    ----------------------------------------------------------

    class GeneralItem extends Page {
       static $db = array(
          "HomeLogo" => "varchar",
          "MainLogo" => "varchar",
          "Abstract" => "Text",
       );
       static $has_one = array(
       );
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', new ImageField('HomeLogo', null, null, null, null, "assets/Uploads/"), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new ImageField('MainLogo', null, null, null, null, "assets/Uploads/"), 'Content');      
          $fields->addFieldToTab('Root.Content.Main', new TextField('Abstract'), 'Content');         
          return $fields;
       }
    }

  • CDGIDev
    Avatar
    Community Member
    9 Posts

    Re: ImageField stays blank Link to this post

    Damn, it was just the field type i had set to varchar! I changed it to text and now it works... :|

  • CDGIDev
    Avatar
    Community Member
    9 Posts

    Re: ImageField stays blank Link to this post

    Oh well, let's continue it's not all fixed it seems...

    Now that my db has been rebuilt, that i installed 2.3.2, i get this when i try to upload an image:

    [Notice] Undefined index:
    POST /images/index/GeneralItem/9/MainLogo/EditImageForm

    Line 157 in /var/www/vhosts/cobi-cdgi.com/httpdocs/sapphire/core/ClassInfo.php

    What can be the cause of this?

    Note: ImageField shows, i can select from the attached files on the server but when i click on attach, i get the aforementionned error....

  • Benedikt
    Avatar
    Community Member
    16 Posts

    Re: ImageField stays blank Link to this post

    You need to define Images in the has_one array.

  • Viv
    Avatar
    Community Member
    30 Posts

    Re: ImageField stays blank Link to this post

    Just wondering about this one too as I get the same 'UNDEFINED INDEX' error if trying to attach image from the file store. My code for this class is below:
    ___________________

    class CdPage extends Page {

    static $db = array(
    'Date' => 'Date',
        'CdName'=> 'Text',
        'CdPrice' => 'Text',
        'CdAbstract' => 'HTMLText',
        'CdDescription' => 'HTMLText'
    );
    static $has_one = array(
    'CdImage' => 'Image'
    );

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

    $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
        $fields->addFieldToTab('Root.Content.CdInfo', new TextField('CdName'));
        $fields->addFieldToTab('Root.Content.CdInfo', new TextField('CdPrice'));
        $fields->addFieldToTab('Root.Content.CdInfo', new HTMLEditorField('CdAbstract'));
        $fields->addFieldToTab('Root.Content.CdInfo', new HTMLEditorField('CdDescription'));
        $fields->addFieldToTab('Root.Content.CdImage', new ImageField('CdCoverImage'));
    return $fields;
    }
    }

    class CdPage_Controller extends Page_Controller {

    }
    ______________

    I am using SS 2.3.3.

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