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   1949 Views

Avatar
CDGIDev

Community Member, 9 Posts

20 June 2009 at 6:08am

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

Community Member, 9 Posts

20 June 2009 at 6:10am

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

Avatar
CDGIDev

Community Member, 9 Posts

20 June 2009 at 6:41am

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

Community Member, 16 Posts

3 September 2009 at 7:54pm

You need to define Images in the has_one array.

Avatar
Viv

Community Member, 30 Posts

18 October 2009 at 12:28pm

Edited: 18/10/2009 12:28pm

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.