Jump to:

23552 Posts in 19349 Topics by 2891 members

General Questions

SilverStripe Forums » General Questions » SOLVED Dataobject with has_many Images, error on edit Dataobject

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

Page: 1
Go to End
Author Topic: 1722 Views
  • danzzz
    Avatar
    Community Member
    175 Posts

    SOLVED Dataobject with has_many Images, error on edit Dataobject Link to this post

    I have a DO product:

    class Product extends DataObject {

    static $db = array(
    'name' => 'Varchar',
    'description' => 'HTMLText',
    'price' => 'Decimal(6,2)',
    );

    static $has_many = array(
    'Images' => 'MyImage'
    );

    public function getCMSFields_forPopup() {

    $images = new MultipleImageUploadField('Images', 'Images');
    $images->removeFolderSelection();
    $images->uploadFolder = 'Uploads/Produktbilder';

    return new FieldSet(
    new TextField('name', 'Produktbezeichnung'),
    new HtmlEditorField('description', 'Produktbeschreibung'),
    new TextField('price', 'Preis'),
    $images
    );
    }

    }

    and a MyImage:

    class MyImage extends File {

    static $has_one = array (
    'Product' => 'Product'
    );

    }

    I added Product to a tab with Dataobjectmanager:

    $fields->addFieldToTab("Root.Content.Produkte", new DataObjectManager(
    $this,
    'Products',
    'Product',
    array(
    'name' => 'Produktbezeichnung',
    'description' => 'Produktbeschreibung',
    'price' => 'Preis'
    ),
    'getCMSFields_forPopup'
    ));

    Now I can add Products, and also the Images to the products. But when I wan to edit the Product:

    [Warning] array_flip() expects parameter 1 to be array, null given
    GET /admin/EditForm/field/Products/item/3/edit?SecurityID=337b36073e9f80cfe044df4c334598fce74b2fad&ctf[Products][start]=0&ctf[Products][per_page]=10&ctf[Products][showall]=0&ctf[Products][sort]=&ctf[Products][sort_dir]=&ctf[Products][search]=&ctf[Products][filter]=

    Line 1334 in /var/www/vhosts/xxx.at/httpdocs/sapphire/core/model/DataObject.php

    1325
    1326 if(!$remoteClass) {
    1327 throw new Exception("Unknown $type component '$component' on class '$this->class'");
    1328 }
    1329
    1330 if($fieldPos = strpos($remoteClass, '.')) {
    1331 return substr($remoteClass, $fieldPos + 1) . 'ID';
    1332 }
    1333
    1334 $remoteRelations = array_flip(Object::combined_static($remoteClass, 'has_one', 'DataObject'));
    1335
    1336 // look for remote has_one joins on this class or any parent classes
    1337 foreach(array_reverse(ClassInfo::ancestry($this)) as $class) {
    1338 if(array_key_exists($class, $remoteRelations)) return $remoteRelations[$class] . 'ID';
    1339 }
    1340

    what could be wrong here?

  • danzzz
    Avatar
    Community Member
    175 Posts

    Re: SOLVED Dataobject with has_many Images, error on edit Dataobject Link to this post

    solved

    I forgot the has_one relation to CategoryPage ...

    1722 Views
Page: 1
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.