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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager i can't get this to work...


Reply


18 Posts   2349 Views

Avatar
zim

Community Member, 135 Posts

18 October 2009 at 11:37am

...as i have created a few different page types with the imagedataobjectmanager and so maybe i am saving files in the wrong tables?? the imagedataobjectmanager in the other pages already has the images from other pages?

Does this make any sense? or have I really messed up and should I just start a new silverstripe project?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

18 October 2009 at 1:22pm

Shouldn't be any reason to start over. Post your code and I can take a look.

Avatar
zim

Community Member, 135 Posts

19 October 2009 at 12:54am

That would be great. really appreciate it.

ok here are three files that I am trying to get to work with imageDataObjectManager.

(It works to the extent that the images appear in the CMS and I can upload images... although it says error on upload. Also seems to pick up all the images already uploaded for another section.... )

when I try to edit image I get this error

"
[User Error] Couldn't run query: SELECT `Imagetest`.*, `Imagetest`.ID, if(`Imagetest`.ClassName,`Imagetest`.ClassName,'Imagetest') AS RecordClassName FROM `Imagetest` WHERE (ParentID = '15') Unknown column 'ParentID' in 'where clause'
"

when I view my ImagetestPage.ss type page i get this error
"
[User Error] Couldn't run query: SELECT `Imagetest`.*, `Imagetest`.ID, if(`Imagetest`.ClassName,`Imagetest`.ClassName,'Imagetest') AS RecordClassName FROM `Imagetest` WHERE (ParentID = '15') Unknown column 'ParentID' in 'where clause'
GET /SilverStripe2/new-imagetestpage/

Line 401 in C:\wamp\www\SilverStripe2\sapphire\core\model\MySQLDatabase.php
"

here are the files..

ImageTest.php

<?php

class Imagetest extends DataObject
{
   static $db = array (
      'Name' => 'Text',
      'Description' => 'Text',
      'Category' => "Enum('Industry, Finance, Education')"
   );
   
   static $has_one = array (
   'ImagetestPage' => 'imagetestPage',
      'Attachment' => 'Image'
      
   );
   
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Name'),
         new TextareaField('Description'),
         new DropdownField('Category','Category', singleton('Imagetest')->dbObject('Category')->enumValues()),
         new FileIFrameField('Attachment')
      );
   }
}

?>

ImageTestPage.php

<?php

class ImagetestPage extends Page
{
   static $has_many = array (
      'Imagetests' => 'Imagetest'
   );
   
   public function getCMSFields()
   {
      $f = parent::getCMSFields();
      $manager = new ImageDataObjectManager(
         $this, // Controller
         'Imagetests', // Source name
         'Imagetest', // Source class
         'Attachment', // File name on DataObject
         array(
            'Name' => 'Name',
            'Description' => 'Description',
            'Category' => 'Category'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
$f->addFieldToTab("Root.Content.Imagetests",$manager);
return $f;
   }

}

class ImagetestPage_Controller extends Page_Controller {

}

?>

and ImageTestPage.ss

<% if Menu(2) %>
<ul id="Menu2">
<% control Menu(2) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the $Title page">$MenuTitle</a></li>
<% end_control %>
</ul>
<% end_if %>

<div id="Content" class="typography">
<% if Level(2) %>
<div class="breadcrumbs">
$Breadcrumbs
</div>
<% end_if %>
      
<h1>$Title</h1>

<% control Imagetests %>
$Description
<% end_control %>

$Content

</div>

...I really appreciate your help. Am I confusing dataobject names with table names? i am clearly a bit confused.

Avatar
zim

Community Member, 135 Posts

19 October 2009 at 1:36am

...is it anything to do with the fact that i am using $manager for all imageDataObjectManager on all the different .php page types??

Avatar
zim

Community Member, 135 Posts

19 October 2009 at 2:26am

...also the above acode seems to work fine with another page that is using the fileDataObjectManager as oppsed to the imageDataObjectManager

Avatar
UncleCheese

Forum Moderator, 4096 Posts

19 October 2009 at 4:34am

The first thing I notice is that there are all kinds of inconsistencies in your naming conventions.

-ImageTest.php contains the class "Imagetest" (lowercase T).

static $has_one = array (
'ImagetestPage' => 'imagetestPage',

- This refers to class "imagetestPage", which doesn't exist, but "ImagetestPage" does.
- ImageTestPage.php contains the class "ImagetestPage" (lowercase T).

Clean all that up, and then drop your tables that relate to these classes, and rebuild. Those tables are probably pretty hosed up by now, and even if they do work, you're going to have a hard time figuring out which foreign key is valid if you ever have to edit these tables in MySQL.

Avatar
zim

Community Member, 135 Posts

19 October 2009 at 6:03am

ok i will do that first...

when you say drp the tables and rebuild what do you mean. I know that dev/build/?flush=1 will rebuild database but how do i "drop" the tables??

Avatar
zim

Community Member, 135 Posts

19 October 2009 at 6:06am

ok so i drop the tables in mysqlmanager. I will do this and rebuild