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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Parent-Child page and dataobject


Go to End


18 Posts   9368 Views

Avatar
Mackodlak

Community Member, 95 Posts

29 June 2011 at 1:31am

Thank you, but again, same error...

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

Avatar
martimiz

Forum Moderator, 1391 Posts

29 June 2011 at 1:46am

Edited: 29/06/2011 2:01am

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']

Avatar
Mackodlak

Community Member, 95 Posts

29 June 2011 at 2:40am

Edited: 29/06/2011 2:42am

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'),

Avatar
martimiz

Forum Moderator, 1391 Posts

29 June 2011 at 4:17am

Edited: 29/06/2011 4:40am

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 ?????????

Avatar
Mackodlak

Community Member, 95 Posts

29 June 2011 at 6:07pm

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

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!

Avatar
Mackodlak

Community Member, 95 Posts

29 June 2011 at 9:22pm

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

Avatar
martimiz

Forum Moderator, 1391 Posts

29 June 2011 at 11:40pm

Edited: 29/06/2011 11:41pm

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

Avatar
Mackodlak

Community Member, 95 Posts

30 June 2011 at 12:06am

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!