7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » DOM + ModelAdmin + Image = strpos error
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1437 Views |
-
DOM + ModelAdmin + Image = strpos error

15 April 2011 at 1:28am
I've tried looking for a solution, and while seeing one or two others with similar issues, I've not seen a solution. I'm using Model Admin for object management, and I'm trying to use ImageDataObjectManager to allow for a has_many relationship to images. When I add images in the DOM when returning to the normal DOM view (i.e. the popup closes) the screen doesn't refresh and show the images. Using the search function in ModelAdmin to see the new item, clicking on it gets a non-stop loading 'swirl' animation and an error along the lines of:
Warning: "strpos() expects parameter 1 to be string, array given" at line 268 of /opt/webapps/shawn/silverstripe2.4/sapphire/core/ViewableData.php
Here is my class for the main object:
ArtCatalogItem.php
<?php
class ArtCatalogItem extends DataObject {
static $db = array(
"ObjectName" => "Varchar(255)",
"AccessionNumber" => "Varchar(255)",
"ArtistMaker" => "Varchar(255)",
"DateOfObject" => "Date",
"Designer" => "Varchar(255)",
"Country" => "Varchar(255)",
"State" => "Varchar(255)",
"City" => "Varchar(255)",
"Techniques" => "Varchar(255)",
"Materials" => "Varchar(255)",
"Colors" => "Varchar(255)",
"StylesTypePattern" => "Varchar(255)",
"Size" => "Varchar(255)",
"Description" => "HTMLText",
"Source" => "Varchar(255)",
"Association" => "Enum('Gift,Loan,Purchase', 'Gift')",
"DateReceived" => "Date",
"DurationOfLoan" => "Varchar(255)",
"Collector" => "Varchar(255)",
"DateCollected" => "Date",
"Condition" => "Enum('Excellent,Good,Fair,Poor,Explain', 'Good')",
"ConditionExplanation" => "HTMLText",
"Location" => "Varchar(255)",
"Value" => "Varchar(255)",
"Remarks" => "HTMLText",
"Correspondence" => "Varchar(255)",
"CatalogReferences" => "Varchar(255)",
"EnteredBy" => "Varchar(255)",
"EnteredDate" => "Date"
);
static $has_many = array(
"Images" => "ArtCatalogImage"
);
static $belongs_many_many = array(
'Collections' => 'ArtCollectionPage'
);
static $summary_fields = array(
'AccessionNumber' => 'Accession Number',
'ObjectName' => 'Object Name'
);
function getCMSFields() {
$f = parent::getCMSFields();
// Code to make collections tab populate from CMS created pages
$collections = DataObject::get('ArtCollectionPage');
$f->addFieldToTab("Root.Collections", new CheckboxSetField('Collections', 'Collections', $collections));
// Code to set up the image manager
$manager = new ImageDataObjectManager(
$this,
'Images',
'ArtCatalogImage',
'ArtImage',
array('Title'),
'getCMSFields_forPopup'
);
$f->addFieldToTab("Root.Images", $manager);
return $f;
}
}
?>And here is my helper class to get details on the image and do a has_one for the image:
ArtCatalogImage.php<?php
class ArtCatalogImage extends DataObject {
static $db = array(
'Title' => 'Varchar(255)',
'Caption' => 'HTMLText'
);
static $has_one = array(
"ArtImage" => "Image",
"ArtCatalogItem" => "ArtCatalogItem"
);
public function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Title'),
new SimpleTinyMCEField('Caption')
);
}
}
?>Silverstripe 2.4.5 and I checked DOM out of GIT yesterday (4/13/11).
Any ideas on why this isn't working? It does seem to be adding things to the database properly, there are records for the images the ArtCatalogItem and the ArtCatalogImage and all the relationships appear to be in place.
Any help will be greatly appreciated, thanks!
-
Re: DOM + ModelAdmin + Image = strpos error

15 April 2011 at 1:34am
Additional info I forgot in the first post:
1. Once this error pops up, it will always pop up. Thus even when hitting the 'create' button in ModelAdmin it errors and doesn't show the form.
2. When deleting an ArtCatalogItem, the associated ArtCatalogImages are not deleted.
3. To make the error stop, I must manually go into the database and remove the ArtCatalogImages.
4. This error doesn't occur at all if I don't attempt to attach any images.
-
Re: DOM + ModelAdmin + Image = strpos error

15 April 2011 at 5:51am
I'm getting the same error. The class utilising Image DOM is below.
class Gallery extends DataObject {
static $db = array(
'Title' => 'Varchar(255)',
'Blurb' => 'Varchar(255)'
);static $has_many = array(
'Fotos' => 'GalleryImage'
);function getCMSFields() {
$fs = parent::getCMSFields();$fs->addFieldToTab('Root.Images', new ImageDataObjectManager($this, 'Fotos', 'GalleryImage', 'Foto'));
return $fs;
}
}Dumping out the $spec variable used inside ViewableData::castingClass() results in the following:
string(7) "Varchar" array(2) { ["Title"]=> string(12) "Varchar(255)" ["Blurb"]=> string(12) "Varchar(255)" }
-
Re: DOM + ModelAdmin + Image = strpos error

5 June 2011 at 8:29am
I've been wrestling with this same error all morning, though not with ModelAdmin. I've got a DOM in a SiteConfig decorator that opens a nested ImageDataObject manager. Same symptoms.
Any thoughts, UncleCheese?
-
Re: DOM + ModelAdmin + Image = strpos error

9 July 2011 at 10:16am
+1 on this issue. My data model is simple:
class Client extends DataObject {
static $db = array('Name' => 'Varchar',
'Challenge' =>'Text',
'Solution' =>'Text',
'Testimonial' =>'Text');static $has_one = array('Logo' => 'Image');
static $has_many = array('Region', 'Service', 'Industry');
static $summary_fields = array('Name',
'Logo');static $searchable_fields = array('Name');
}And I am having this issue
-
Re: DOM + ModelAdmin + Image = strpos error

12 July 2011 at 1:48am Last edited: 12 July 2011 1:49am
This may or may not work for others, but my solution was to remove the array of fields to be displayed in the DOM:
Original -
// Code to set up the image manager
$manager = new ImageDataObjectManager(
$this,
'Images',
'ArtCatalogImage',
'ArtImage',
array('Title'),
'getCMSFields_forPopup'
);
$f->addFieldToTab("Root.Images", $manager);New -
// Code to set up the image manager
$manager = new ImageDataObjectManager(
$this,
'Images',
'ArtCatalogImage',
'ArtImage',
'',
'getCMSFields_forPopup'
);
$f->addFieldToTab("Root.Images", $manager); -
Re: DOM + ModelAdmin + Image = strpos error

7 January 2012 at 11:09am Last edited: 7 January 2012 11:15am
Hi Shawn,
Have you tried formatting your array in your ImageDataObjectManager like this:
array('Title' => 'Title'),
I got this error whilst using a ComplexTableField not DataObjectManager so not sure if this will help but it is worth a try.
Thanks,
Jim
-
Re: DOM + ModelAdmin + Image = strpos error

24 January 2012 at 11:53am
Thanks Jim
That worked for me.
| 1437 Views | ||
|
Page:
1
|
Go to Top |





