Hi all,
I am in a bit of a tight spot here. I need to figure out how to be able to add images to the DOM. I took some of the sample code from the Testimonials tutorial and modified it a bit.
What I want to do is have images attached to the record entry and then be able to display them on the my site. I have manged to do this and it works but every time i rebuild the database i get this error. This a bad thing because every time I make changes to my code silverstripe get stuck on that error and wont recognize the changes made.
Error:
[Warning] DataObject::__construct passed The value 'Photo'. It's supposed to be passed an array, taken straight from the database. Perhaps you should use DataObject::get_one instead?
GET /bingham/dev/build?flush=1
Line 197 in C:\wamp\www\bingham\sapphire\core\model\DataObject.php
Source
188 'RecordClassName' => get_class($this)
189 );
190 }
191
192 if(!is_array($record)) {
193 if(is_object($record)) $passed = "an object of type '$record->class'";
194 else $passed = "The value '$record'";
195
196 user_error("DataObject::__construct passed $passed. It's supposed to be passed an array,
197 taken straight from the database. Perhaps you should use DataObject::get_one instead?", E_USER_WARNING);
198 $record = null;
199 }
200
201 $this->record = $this->original = $record;
202
203 // Keep track of the modification date of all the data sourced to make this page
Code: Product.php
<?php
class Product extends DataObject
{
static $db = array (
'Date' => 'Date',
'Author' => 'Text',
'Quote' => 'HTMLText',
'Photo' => 'Image'
);
static $has_one = array (
'ProductPage' => 'ProductPage',
'Photo' => 'Image'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new CalendarDateField('Date'),
new TextField('Author'),
new TextareaField('Quote'),
new ImageField('Photo')
);
}
}
?>
ProductPage.php
<?php
class ProductPage extends Page
{
static $has_many = array (
'Products' => 'Product',
'Photo' => 'Image'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Products", new DataObjectManager(
$this,
'Products',
'Product',
array('Date' => 'Date','Author'=>'Author','Quote' => 'Quote','Photo' => 'Photo'),
'getCMSFields_forPopup'
));
return $f;
}
}
class ProductPage_Controller extends Page_Controller {
}
?>
If any one has any suggestions please let me know. I would appreciate all the help i can get thanks in advance.