21308 Posts in 5737 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 1493 Views |
-
[SOLVED] ImageID won't record anymore

5 August 2010 at 4:13pm Last edited: 29 September 2010 1:47am
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;
$p->write();
}
Director::redirectBack();
return;
}
}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.
-
Re: [SOLVED] ImageID won't record anymore

8 August 2010 at 5:46am
Alright,
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?).Barry
-
Re: [SOLVED] ImageID won't record anymore

8 August 2010 at 11:53am
Yes, the rest of the items get written correctly.
Here is the DataObject code:
<?php
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)
);
}
} -
Re: [SOLVED] ImageID won't record anymore

8 August 2010 at 11:03pm Last edited: 8 August 2010 11:07pm
I'd have to say I am stumped too, all looks fine, did you try...
$p->setComponent('Image',DataObject::get_by_id('Image',$id));
or
$p->setField('Image',$id);
(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... http://silverstripe.org/data-model-questions/show/289206#post289206... if possible could you post an outline of your method please?
Barry
-
Re: [SOLVED] ImageID won't record anymore

11 August 2010 at 8:07am
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/domain.com/httpdocs/sapphire/core/control/Controller.php on line 162 and defined
POST /Account/addPhotosLine 457 in /var/www/vhosts/domain.com/httpdocs/mysite/code/Account.php
Source448 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 }
456
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'];Trace
* 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 -
Re: [SOLVED] ImageID won't record anymore

11 August 2010 at 6:28pm
change...
public function addPhotos($data,$form)
to...public function addPhotos($data)
? -
Re: [SOLVED] ImageID won't record anymore

11 August 2010 at 6:33pm
Tried that already, didn't fix it.
| 1493 Views | ||
| Go to Top | Next > |


