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

SS3 Beta UploadField on DataObject issues


Reply


2 Posts   595 Views

Avatar
nimesodelta

Community Member, 21 Posts

22 March 2012 at 10:04pm

Edited: 22/03/2012 10:06pm

Hi All,

Not sure if I'm missing something here or maybe someone can tell me this is a know issue.

I have a simple DataObject called 'Brand' like so...

class Brand extends DataObject {

   static $db = array(
      "Title" => "Varchar(256)",
      "WebsiteLink" => "Varchar(256)"
   );

   public static $has_one = array(
      "HomePage" => "HomePage",
      "Logo" => "Image"
   );

   public static $summary_fields = array(
      'Title'
   );
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab("Root.Main", new TextField("Title", "Title"));
      $fields->addFieldToTab("Root.Main", new TextField("WebsiteLink", "Website Link"));
      $fields->addFieldToTab("Root.Main", new UploadField("Logo"));
      $fields->removeFieldFromTab("Root.Main", "HomePageID");
      return $fields;
   }
   
}

And 'Brands' can be added to a page using the new GridField like:

$brandsConfig = new GridFieldConfig_RelationEditor();
$brandsTable = new GridField("Brands","Brands",$this->Brands(),$brandsConfig);

everything so far is cool BUT when I try to attach a image to a 'Brand' object (adding or editing) it seems the form action is messing up and the DataObject has no controller action kicking in to deal with the 'upload' method... it returns a 404.... eg:

http://zqpublic.nimeso/admin/page/edit/EditForm/field/Brands/item/1/ItemEditForm/field/Logo/upload (Wont work)

http://zqpublic.nimeso/admin/page/edit/EditForm/field/HeaderImage/upload (Will work - used in my base Page class)

Cheers guys! Great job so far! looking Asum!

Avatar
Phat

Community Member, 8 Posts

21 May 2012 at 11:13am

Hi nimesodelta,

The problem is that when an image is uploaded, it cannot make a link (LogoID) back to Brand dataobject since the Brand has not been actually created at the time the image is uploaded. A Brand data object is actually created when you click Create button.

If you try to save (create) a Brand first and then upload a image, it works fine...I know this is not a solution but hope the info is helpful.

Let me know if you can fix the problem

Cheers,