Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

ImageField stays blank


Reply

5 Posts   1889 Views

Avatar
CDGIDev

20 June 2009 at 6:08am Community Member, 9 Posts

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

Avatar
CDGIDev

20 June 2009 at 6:10am Community Member, 9 Posts

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

Avatar
CDGIDev

20 June 2009 at 6:41am Community Member, 9 Posts

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

Avatar
Benedikt

3 September 2009 at 7:54pm Community Member, 16 Posts

You need to define Images in the has_one array.

Avatar
Viv

18 October 2009 at 12:28pm (Last edited: 18 October 2009 12:28pm), Community Member, 30 Posts

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.