7919 Posts in 1358 Topics by 932 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager model problem (updated)
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: | 1618 Views |
-
ImageDataObjectManager model problem (updated)

16 December 2009 at 8:32am Last edited: 18 December 2009 7:40am
Edited to show the updated code.
ProjectHolder.php
<?php
class ProjectHolder extends Page {
static $allowed_children = array(
'Project'
);
static $singular_name = 'Project Holder';
static $plural_name = 'Project Holders';
static $has_many = array(
'Projects' => 'Project'
);
}
class ProjectHolder_Controller extends Page_Controller {}
?>Project.php
<?php
class Project extends Page {
static $singular_name = 'Project';
static $plural_name = 'Projects';
static $db = array(
'Category' => 'Varchar(100)',
'Description' => 'Text'
);
static $has_one = array(
'ProjectHolder' => 'ProjectHolder',
'Thumbnail' => 'Crop_Thumbnail'
);
static $has_many = array(
'Attachments' => 'Attachment'
);
public function getCMSFields() {
$categories = array(
'Web Design' => 'Web Design',
'Web Development' => 'Web Development',
'Graphic Design' => 'Graphic Design',
'Illustration' => 'Illustration',
'Photography' => 'Photography'
);
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Content.Main','Content');
$fields->addFieldToTab('Root.Content.Main', new DropdownField('Category','Category', $categories));
$fields->addFieldToTab('Root.Content.Main', new TextareaField('Description'));
$fields->addFieldToTab('Root.Content.Thumbnail Image', new ImageField('Thumbnail'));
$attachmentTable = new ComplexTableField(
$controller = $this,
$name = 'Attachments',
$sourceClass = 'Attachment',
$fieldList = array(
'Title' => 'Title',
'Caption' => 'Caption'
)
);
$fields->addFieldToTab('Root.Content.Attachments', $attachmentTable);
return $fields;
}
}
class Crop_Thumbnail extends Image {
function generateProjectThumbnail($gd) {
return $gd->resizeByWidth(200);
}
}
class Project_Controller extends Page_Controller {}
?>Attachment.php
<?php
class Attachment extends DataObject {
static $db = array(
'Title' => 'Text',
'Caption' => 'Text',
);
static $has_one = array(
'Project' => 'Project',
'AttachmentImage' => 'Image'
);
public function getCMSFields(){
return new FieldSet(
new TextField('Title'),
new TextareaField('Caption'),
new ImageField('AttachmentImage')
);
}
}
?> -
Re: ImageDataObjectManager model problem (updated)

16 December 2009 at 8:53am
Yikes.. Your model is a mess. Explain what you're trying to do and I can point you in the right direction.
-
Re: ImageDataObjectManager model problem (updated)

16 December 2009 at 9:00am
Haha, I expected as much. I have ProjectHolder(extends Page) which can hold many Projects(extends Page). Each page has one Gallery(extends DataObject), which can in turn hold many different Attachments(extends DataObject). The ProjectHolder is to serve as a general portfolio that displays the specified Thumbnail from each Project. When clicking a Thumbnail in the ProjectHolder, the Project page is then loaded which displays the full Gallery for that Project(among other info, such as the Project category and a brief description). The Gallery is comprised of many different Attachments, each of which have a title, caption, and image.
-
Re: ImageDataObjectManager model problem (updated)

18 December 2009 at 7:01am
So I started from scratch and eliminated a lot of unnecessary code in the Model and has updated my first post with the revised code. Everything is working great, except I am getting two separate error messages when I attempt to upload images as as ThumbnailImage and as an Attachment.
ThumbnailImage upload error:
[User Error] Couldn't run query: SELECT `File`.*, `Gallery`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` LEFT JOIN `Gallery` ON `Gallery`.ID = `File`.ID WHERE (`File`.`ID` = 1) ORDER BY SortOrder ASC LIMIT 1 Column 'SortOrder' in order clause is ambiguous
GET /public_html/jonathandbaker.com/images/iframe/Project/15/ThumbnailLine 401 in D:\xampp\xampp\htdocs\public_html\jonathandbaker.com\sapphire\core\model\MySQLDatabase.php
Source392 }
393
394 function databaseError($msg, $errorLevel = E_USER_ERROR) {
395 // try to extract and format query
396 if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
397 $formatter = new SQLFormatter();
398 $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
399 }
400
401 user_error($msg, $errorLevel);
402 }
403 }
404
405 /**
406 * A result-set from a MySQL database.
407 * @package sapphireTrace
* Couldn't run query: SELECT `File`.*, `Gallery`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` LEFT JOIN `Gallery` ON `Gallery`.ID = `File`.ID WHERE (`File`.`ID` = 1) ORDER BY SortOrder ASC LIMIT 1 Column 'SortOrder' in order clause is ambiguous
Line 401 of MySQLDatabase.php
* MySQLDatabase->databaseError(Couldn't run query: SELECT `File`.*, `Gallery`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` LEFT JOIN `Gallery` ON `Gallery`.ID = `File`.ID WHERE (`File`.`ID` = 1) ORDER BY SortOrder ASC LIMIT 1 | Column 'SortOrder' in order clause is ambiguous,256)
Line 102 of MySQLDatabase.php
* MySQLDatabase->query(SELECT `File`.*, `Gallery`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` LEFT JOIN `Gallery` ON `Gallery`.ID = `File`.ID WHERE (`File`.`ID` = 1) ORDER BY SortOrder ASC LIMIT 1,256)
Line 120 of DB.php
* DB::query(SELECT `File`.*, `Gallery`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` LEFT JOIN `Gallery` ON `Gallery`.ID = `File`.ID WHERE (`File`.`ID` = 1) ORDER BY SortOrder ASC LIMIT 1)
Line 426 of SQLQuery.php
* SQLQuery->execute()
Line 2531 of DataObject.php
* DataObject->instance_get_one(`File`.`ID` = 1,)
Line 2468 of DataObject.php
* DataObject::get_one(File,`File`.`ID` = 1)
Line 2563 of DataObject.php
* DataObject::get_by_id(File,1)
Line 1045 of DataObject.php
* DataObject->getComponent(Parent)
* call_user_func_array(Array,Array)
Line 565 of Object.php
* Object->__call(Parent,Array)
* Crop_Thumbnail->Parent()
Line 279 of Image.php
* Image->cacheFilename(CMSThumbnail,,)
Line 261 of Image.php
* Image->getFormattedImage(CMSThumbnail)
Line 211 of Image.php
* Image->CMSThumbnail()
* call_user_func_array(Array,Array)
Line 408 of ViewableData.php
* ViewableData->XML_val(CMSThumbnail,,1)
Line 56 of .cacheD..xampp.xampp.htdocs.public_html.jonathandbaker.com.sapphire.templates.Image_iframe.ss
* include(C:\Windows\Temp\silverstripe-cacheD--xampp-xampp-htdocs-public_html-jonathandbaker.com\.cacheD..xampp.xampp.htdocs.public_html.jonathandbaker.com.sapphire.templates.Image_iframe.ss)
Line 357 of SSViewer.php
* SSViewer->process(ViewableData_Customised)
Line 163 of Controller.php
* Controller->handleAction(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 119 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/images/iframe/Project/15/Thumbnail)
Line 118 of main.phpAttachment upload error:
[Warning] Unknown class passed as parameter
POST /public_html/jonathandbaker.com/images/index/Attachment/5/AttachmentImage/EditImageFormLine 445 in D:\xampp\xampp\htdocs\public_html\jonathandbaker.com\sapphire\core\Object.php
Source436 * Prepare static variables before processing a {@link get_static} or {@link set_static}
437 * call.
438 */
439 private static function prepare_statics($class) {
440 // _cache_statics_prepared setting must come first to prevent infinite loops when we call
441 // get_static below
442 self::$_cache_statics_prepared[$class] = true;
443
444 // load statics now for DataObject classes
445 if(is_subclass_of($class, 'DataObject')) {
446 $extensions = Object::uninherited_static($class, 'extensions');
447 if($extensions) foreach($extensions as $extension) {
448 if(preg_match('/^([^(]*)/', $extension, $matches)) {
449 $extensionClass = $matches[1];
450 DataObjectDecorator::load_extra_statics($class, $extensionClass);
451 }Trace
* is_subclass_of(Crop_Thumbnail,DataObject)
Line 445 of Object.php
* Object::prepare_statics(Crop_Thumbnail)
Line 269 of Object.php
* Object::uninherited_static(Crop_Thumbnail,db)
Line 2020 of DataObject.php
* DataObject::has_own_table(Crop_Thumbnail)
Line 89 of ClassInfo.php
* ClassInfo::dataClassesFor(Image)
Line 2258 of DataObject.php
* DataObject->buildSQL(,,,,1,)
Line 2350 of DataObject.php
* DataObject->extendedSQL(,,,,)
Line 566 of File.php
* File->instance_get(,,,,DataObjectSet)
Line 2387 of DataObject.php
* DataObject::get(Image)
Line 58 of SortableDataObject.php
* SortableDataObject->onBeforeWrite(,,,,,,)
Line 802 of Object.php
* Object->extend(onBeforeWrite,)
Line 665 of DataObject.php
* DataObject->onBeforeWrite()
Line 251 of File.php
* File->onBeforeWrite()
Line 783 of DataObject.php
* DataObject->write()
Line 133 of Upload.php
* Upload->load(Array,)
Line 151 of Upload.php
* Upload->loadIntoFile(Array,Image)
Line 226 of File.php
* File->loadUploaded(Array)
Line 123 of Image.php
* Image->loadUploaded(Array)
Line 748 of Image.php
* Image_Uploader->save(Array,Form,HTTPRequest)
Line 241 of Form.php
* Form->httpSubmission(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 143 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 119 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/images/index/Attachment/5/AttachmentImage/EditImageForm)
Line 118 of main.php -
Re: ImageDataObjectManager model problem (updated)

18 December 2009 at 8:21am
That could be a lot of things. Looks like your File subclass got a SortOrder column on it, which it shouldn't have since File is a sortable class to begin with. If you've made a lot of changes to your model, your best bet is to scrap the database and start over because Silverstripe doesn't delete obsolete fields.
-
Re: ImageDataObjectManager model problem (updated)

18 December 2009 at 8:57am
Thanks again UC... cheers!
| 1618 Views | ||
|
Page:
1
|
Go to Top |

