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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

How To Debug this error? Unknown class passed as parameter


Go to End


4 Posts   3182 Views

Avatar
biapar

Forum Moderator, 435 Posts

28 December 2009 at 11:37am

Into Product.php class file; I write:

class ResizeImage extends Image {
static $db = null;

function generateThumbnail($gd) {
$gd->setQuality(80);
return $gd->paddedResize(140,100);
}

function generateContentImage($gd) {
$gd->setQuality(90);
return $gd->resizeByWidth(200);
}

function generateLargeImage($gd) {
$gd->setQuality(90);
return $gd->resizeByWidth(600);
}

}

class ImageAttachment extends DataObject {
static $db = array(
'Name' => 'Text'
);
/* static $has_one = array(
'Image' => 'ResizeImage',
);
*/
static $has_one = array(
'Image' => 'ResizeImage',
'Product' => 'Product'
);
//<img class="headerImage" src="$Image.Thumbnail.URL" >
static $field_names = array('Thumbnail' => 'Image','Name' => 'Name');

function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push(new TextField('Name', 'Name'));
$fields->push(new ImageField('Image', 'Image'));

return $fields;
}

function Thumbnail() {
$Image = $this->Image();
if ( $Image ) {
return $Image->CMSThumbnail();
} else {
return null;
}
}

}

and

class Product extends Page {.....

static $has_many = array(
'ImageAttachments' => 'ImageAttachment'
);

....

$my_imagetable = new DataObjectManager(
$this,
'ImageAttachments',
'ImageAttachment',
ImageAttachment::$field_names,
ImageAttachment::getCMSFields_forPopup(), // form that pops up for edit
"ProductID = {$this->ID}", // a filter to only display item associated with this page
"Name ASC" // Sort by name
);

// $fields->addFieldToTab('Root.Content.Additional Images', $imagetable);
$fields->addFieldToTab('Root.Content.Additional Images', $my_imagetable);

...}

but when popup open for adding new image, I had this error at place of upload image field.

[Warning] Unknown class passed as parameter
GET /images/iframe/ImageAttachment/36/Image

Line 2553 in /var/www/clients/client1/web12/web/sapphire/core/model/DataObject.php
Source

2544 * Return the given element, searching by ID
2545 *
2546 * @param string $callerClass The class of the object to be returned
2547 * @param int $id The id of the element
2548 *
2549 * @return DataObject The element
2550 */
2551 public static function get_by_id($callerClass, $id) {
2552 if(is_numeric($id)) {
2553 if(is_subclass_of($callerClass, 'DataObject')) {
2554 $tableClasses = ClassInfo::dataClassesFor($callerClass);
2555 $baseClass = array_shift($tableClasses);
2556 return DataObject::get_one($callerClass,"`$baseClass`.`ID` = $id");
2557
2558 // This simpler code will be used by non-DataObject classes that implement DataObjectInterface
2559 } else {

Trace

* is_subclass_of(ImageAttachment,DataObject)
Line 2553 of DataObject.php
* DataObject::get_by_id(ImageAttachment,36)
Line 533 of Image.php
* Image_Uploader->linkedObj()
Line 548 of Image.php
* Image_Uploader->Image()
Line 562 of Image.php
* Image_Uploader->IsImage()
Line 597 of Image.php
* Image_Uploader->EditImageForm()
* call_user_func_array(Array,Array)
Line 408 of ViewableData.php
* ViewableData->XML_val(EditImageForm,,1)
Line 983 of ViewableData.php
* ViewableData_Customised->XML_val(EditImageForm,,1)
Line 37 of .cache.var.www.clients.client1.web12.web.sapphire.templates.Image_iframe.ss
* include(/tmp/silverstripe-cache-var-www-redconsulting.it-web/.cache.var.www.clients.client1.web12.web.sapphire.templates.Image_iframe.ss)
Line 354 of SSViewer.php
* SSViewer->process(ViewableData_Customised)
Line 166 of Controller.php
* Controller->handleAction(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/images/iframe/ImageAttachment/36/Image)
Line 118 of main.php

How resolve?

Thanks

Avatar
biapar

Forum Moderator, 435 Posts

29 December 2009 at 3:40am

No Help?

Avatar
biapar

Forum Moderator, 435 Posts

29 December 2009 at 3:40am

No Help?

Avatar
biapar

Forum Moderator, 435 Posts

30 December 2009 at 6:31am

I had resolved.
File product.php

class Product_ImageAttachment extends DataObject {

class Product_ImageAttachment extends DataObject {
static $db = array(
'Name' => 'Text'
);

/* static $has_one = array(
'Image' => 'ResizeImage',
);
*/
static $has_one = array(
'Image' => 'Product_ResizeImage',
'Product' => 'Product'
);
//<img class="headerImage" src="$Image.Thumbnail.URL" >
static $field_names = array('Thumbnail' => 'Image','Name' => 'Name');

public function getCMSFields_forPopup() {

$fields = new FieldSet();
$fields->push(new TextField('Name', 'Name'));
$fields->push(new ImageField('Image', 'Image'));

return $fields;
}

function Thumbnail() {
$Image = $this->Image();
if ( $Image ) {
return $Image->CMSThumbnail();
} else {
return null;
}
}

}

Into class Product extends Page :

static $has_many = array(
'ProductImageAttachments' => 'Product_ImageAttachment'
);

$my_imagetable = new DataObjectManager(
$this,
'ProductImageAttachments',
'Product_ImageAttachment',
Product_ImageAttachment::$field_names,
Product_ImageAttachment::getCMSFields_forPopup(), // form that pops up for edit
"ProductID = {$this->ID}", // a filter to only display item associated with this page
"Name ASC" // Sort by name
);
....ecc..

Bye Bye