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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[SOLVED] ImageID won't record anymore

Go to End

15 Posts   2100 Views

Ryan M.

5 August 2010 at 4:13pm (Last edited: 29 September 2010 1:47am), Community Member, 309 Posts

I have a photo uploader using SWFUpload to insert images into a Photo DataObject. See code below:

public function addPhotos($data,$form)
      if(isset($data['uploaded_files']) && is_array($data['uploaded_files']) && isset($data['AlbumID'])) {
         foreach($data['uploaded_files'] as $id) {
            $p = new Photo();
            $p->AlbumID = $data['AlbumID'];
            $p->MemberPageID = $this->Member()->MemberPageID;
            $p->ImageID = $id;

The problem is that the ImageID does not get written to its own column in the Photo database table. The File class gets created just fine, the file appears in the assets/Uploads folder. I even echoed $id to find out if it was being passed at all, and yes it is.

I'm stumped.


8 August 2010 at 5:46am Forum Moderator, 1796 Posts


Are the rest of the photo items getting written correctly? Do you have the Photo DataObject to see the code?
I've had this issue when the name of the field was wrong or I had a conflicting function checking the database and then using $p-setField('Name','Value') might help. Or you could try using the setComponent function to set the has_one (it is a has_one isn't it?).


Ryan M.

8 August 2010 at 11:53am Community Member, 309 Posts

Yes, the rest of the items get written correctly.

Here is the DataObject code:


class Photo extends DataObject
   static $db = array (
      'Title' => 'Text',
      'Caption' => 'Text',
      'Votes' => 'Int'
   static $has_one = array (
      'MemberPage' => 'MemberPage',
      'Image' => 'Image',
      'Album' => 'PhotoAlbum',
      'EventPage' => 'EventPage'
   static $has_many = array (
      'Comments' => 'Comment'

   public function DeleteLink()
      return Director::link("Account/deletephoto/$this->ID");
   public function Link()
      return $this->MemberPage()->Link("showphoto/$this->ID");
   public function EventLink()
      if($this->EventPage()) {
         return $this->EventPage()->Link("showphoto/$this->ID");
   public function getCMSFields()
      return new FieldSet(
         new TextField('Title'),
         new TextareaField('Caption'),
         new ImageField('Image'),
         new DataObjectManager($this)


8 August 2010 at 11:03pm (Last edited: 8 August 2010 11:07pm), Forum Moderator, 1796 Posts

I'd have to say I am stumped too, all looks fine, did you try...



(or $p->setField('ImageID',$id);)

also did you debug show / log the data object before the write and then compare it to one that you 'get' with the right value?

Out of interest is your photo uploader part of the DOM or is it possible to use it in ModelAdmin? I am very interested in a nice way for a user (public side) and admin (cms side) to upload a bunch of photos... if possible could you post an outline of your method please?


Ryan M.

11 August 2010 at 8:07am Community Member, 309 Posts

I use the DOM for this, so no I don't interface directly with ModelAdmin.

$p->setField('ImageID',$id) didn't work.

I added Debug::show() and put the site in dev mode to capture errors. This is what I got:

[Warning] Missing argument 2 for Account::addPhotos(), called in /var/www/vhosts/ on line 162 and defined
POST /Account/addPhotos

Line 457 in /var/www/vhosts/

448             new LiteralField("uploadWarn", "<div class=\"uploadWarn\">Your photos must be resized to 1200x1200 pixels or smaller and take up no more than 5mb of disk space each.</div>"),
449             new FormAction('addPhotos','Upload')
450          )
451       );
452       if(isset($this->urlParams['ID']))
453          $fields->push(new HiddenField('AlbumID','',$this->CurrentAlbum()->ID));
454       return $f;
455    }
457    public function addPhotos($data,$form)
458    {
459       if(isset($data['uploaded_files']) && is_array($data['uploaded_files']) && isset($data['AlbumID'])) {
460          Debug::show();
461          foreach($data['uploaded_files'] as $id) {
462             $p = new Photo();
463             $p->AlbumID = $data['AlbumID'];


* Account->addPhotos(HTTPRequest)
Line 162 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(/Account/addPhotos)
Line 118 of main.php


11 August 2010 at 6:28pm Forum Moderator, 1796 Posts


public function addPhotos($data,$form)


public function addPhotos($data)


Ryan M.

11 August 2010 at 6:33pm Community Member, 309 Posts

Tried that already, didn't fix it.


11 August 2010 at 6:49pm Forum Moderator, 1796 Posts

you got the same error?

Go to Top