Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager i can't get this to work...

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 2215 Views
  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    ...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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

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

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    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.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

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

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    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.

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

    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??

  • zim
    Avatar
    Community Member
    135 Posts

    Re: ImageDataObjectManager i can't get this to work... Link to this post

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

    2215 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.