Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Parent-Child page and dataobject

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

Page: 1 2 3
Go to End
Author Topic: 3446 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Parent-Child page and dataobject Link to this post

    Thank you, but again, same error...

    Not sure what I'm doing wrong... but I guess sth is not as it should be

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Parent-Child page and dataobject Link to this post

    Oh... I'm truely sorry, should be

    $this->requestParams['ID']

    Is an array, must be the heat

    [EDIT] oh, and as you're using a simulated url like /ss/svijet-sigurnosti/lotd/post/45/ you could try $this->urlParams['ID']

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Parent-Child page and dataobject Link to this post

    pff... I truly am thankful for your help, but:

    $this->urlParams['ID']; give following error:

    [Warning] reset() expects parameter 1 to be array, null given
    GET /ss/svijet-sigurnosti/lotd/post/45/

    Line 102 in /var/www/ss/sapphire/core/ClassInfo.php
    Source

    93     * Return the root data class for that class.
    94     * This root table has a lot of special use in the DataObject system.
    95     *
    96     * @param mixed $class string of the classname or instance of the class
    97     * @return array
    98     */
    99    static function baseDataClass($class) {
    100       global $_ALL_CLASSES;
    101       if (is_object($class)) $class = get_class($class);
    102       reset($_ALL_CLASSES['parents'][$class]);
    103       while($val = next($_ALL_CLASSES['parents'][$class])) {
    104          if($val == 'DataObject') break;
    105       }
    106       $baseDataClass = next($_ALL_CLASSES['parents'][$class]);
    107       return $baseDataClass ? $baseDataClass : $class;
    108    }

    and $this->requestParams['ID'] ; gives this one:

    [Notice] Undefined index: ID
    GET /ss/svijet-sigurnosti/lotd/post/45/

    Line 63 in /var/www/ss/mysite/code/LOTDPage.php
    Source

    54 /* sa 2 polja za unos teksta
    55 /* Lname i LOTD
    56 /*
    57 */
    58
    59
    60 function LOTDEntryForm() {
    61
    62    $ID = 0;
    63    if($this->requestParams['ID']){
    64       $ID = (int) $this->requestParams['ID'];
    65    }
    66
    67 // Create fields
    68 $fields = new FieldSet(
    69     new TagField('Tags', null, null, 'LOTD'),

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Parent-Child page and dataobject Link to this post

    The question remaining: does your form receive the ID at all? Maybe test this using echo "ID = " . $ID; die(); right after your $ID = something statement...

    If this doesn't help - I might install your code tomorrow between things - unless you get it working of course - for me this working day is now ended

    [EDIT] OK, needed to wait for a friend, so i installed it (245). Didn't have the TagField object, that gave an error, so I removed it from the form and the object. Changed only that, nothing else. Saw no error, details are loaded into the form nicely. So it's not the things I came up with....

    Only thing is that it won't update an existing form but still creates a new record. But that's another thing. So maybe the problem is in the TagField ?????????

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Parent-Child page and dataobject Link to this post

    OMG it works
    So the only problem was in fact tagfield?
    And I can't even find a way to use that tagfield
    Man, you don't know how frustrating it was to try and find what I did wrong... I was sure it should work

    Thank you again.

    Now, the only thing that remains is to be able to search the LOTDs , but I will have to add some description or tags or sth for that...

    Anyways thank you!

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Parent-Child page and dataobject Link to this post

    Well I was celebrating 2 soon it seems.

    Now the link does work, and new page is rendered with form and I can change the data, but I figured it just creates a new DB entry instead changing the existing one.
    Now this clearly isn't what I need so once again I looked into blog module how I should change my PostLOTD function so it rly does edit the existing one.

    I came by thins:

    function PostLOTD($data, $form){

       $LOTD = false;

       if(isset($data['ID']) && $data['ID']) {
          $LOTD = DataObject::get_by_id("LOTD", $data['ID']);
    //      if(!$LOTD->IsOwner()) {
    //         unset($LOTD);
    //      }
       }

       if(!$LOTD) {
          $LOTD = new LOTD();
       }

        $form->saveInto($LOTD);
    $LOTD->write();
    $this->redirect('.');
    }

    But it still just creates a new DB entry... I figured that if(isset($data['ID']) && $data['ID']) { is doing sth wrong, don't rly understand what or why...

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Parent-Child page and dataobject Link to this post

    Yep, the next step

    In this case $data['ID'] will only have the ID if you add some (hidden) ID field to the form and set it to the ID value...

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: Parent-Child page and dataobject Link to this post

    This is like awsome...

    Looked in BlogHolder.php, and sure enough there is this one field in fieldset:
    $fields = new FieldSet(
        new HiddenField("ID", "ID"),
    ...
    );

    , and sure enough it made all the difference, now it works perfectly.
    Thanks again mate...

    TBH this webpage is the first one i'm building, am kinda new to php, and SilverStripe so I take things one step at a time.
    Sure, there are loads of docs, tutorials and modules/widgets to help me, but still need a lot to figure out.

    Mate you have helped me a lot... Works like a charm!

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