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 /

Can't add images to the CMS


Reply


3 Posts   1295 Views

Avatar
DanStephenson

Community Member, 116 Posts

13 February 2009 at 5:44am

Greetings folks,

I'm working on my first SilverStripe powered site. I am building a layout that is going to have several different tabs in the CMS, each for a different type of data. One of these tabs, "Resellers", should allow for the user to upload 4 reseller logos, to be displayed at the bottom of the page.

I am using this code inside my HomePage.php file:

class HomePage extends Page {
'Reseller1' => 'Image',
'Reseller2' => 'Image',
'Reseller3' => 'Image',
'Reseller4' => 'Image'
}

function getCMSFields() {
$fields->addFieldToTab('Root.Content.Resellers', new ImageField('Reseller1', 'Reseller Logo 1'));
$fields->addFieldToTab('Root.Content.Resellers', new ImageField('Reseller2', 'Reseller Logo 2'));
$fields->addFieldToTab('Root.Content.Resellers', new ImageField('Reseller3', 'Reseller Logo 3'));
$fields->addFieldToTab('Root.Content.Resellers', new ImageField('Reseller4', 'Reseller Logo 4'));
}

And when I run my /db/build/?flush=1 I get this error message:

FATAL ERROR: DataObject::__construct passed The value 'Reseller1'. It's supposed to be passed an array, taken straight from the database. Perhaps you should use DataObject::get_one instead?
At line 83 in C:\wamp\www\valtus-ss\sapphire\core\model\DataObject.php

Can anyone help me solve this issue?

Avatar
Fuzz10

Community Member, 787 Posts

13 February 2009 at 10:15pm

You need to link your images to your class by defining a relationship.

e.g.
static $has_one = array(
      'Thumbnail' => 'Image',
   );

Avatar
Carbon Crayon

Community Member, 598 Posts

13 February 2009 at 11:59pm

Hi Dan

I'd recommend going through tutorials 1 and 2 to see how these things work.

http://doc.silverstripe.org/doku.php?id=tutorial:1-building-a-basic-site

http://doc.silverstripe.org/doku.php?id=tutorial:2-extending-a-basic-site