Hi,
I build portal and i have a problem with dataobject in frontend
Can someone help me?
Generally everything works fine except fuction to save "dosave"
Sorry for my bad English
Obsolete - updated the code below
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Hi,
I build portal and i have a problem with dataobject in frontend
Can someone help me?
Generally everything works fine except fuction to save "dosave"
Sorry for my bad English
Obsolete - updated the code below
Maybe I write differently.
Code is based on the module forum.
In code module forum after delete unnecessary code i have code - attach file (ForumCode.php):
Based on this code I create this code: attach file (myCode.php)
Has anyone an idea?
Generally, in frontend i have form to edit "obiekt" with right ID but when i click save changes is not save.
Editting adress: www.mysite/edytuj/edit/30
30 - sample ID Object to edit
when I click save changes i have www.mysite/edytuj/EditObiektForm, should be www.mysite/edytuj/thanks and should be save :)
Generally runs most of the exception object save.
I think that i bad write function dosave or getObiekt, something does not work in get by ID - i think
Sorry for my bad English
Ok,
I found half of the error:
I limited allow action - now i delete this.
Now when I click save change i have error
Fatal error: Call to a member function getObiektFields() on a non-object in www.mysite.pl/obiekty/code/EditObiektPage.php on line 40
Probably function getObiekt() is wrong write
ObiektRole.php (here is function getObiektFields())
<?php
class ObiektRole extends DataObjectDecorator {
function extraStatics() {
$fields = array(
'db' => array(
'City' => 'Varchar'
),
'has_one' => array(
'Avatar' => 'Image'
)
);
return $fields;
}
function getObiektFields() {
$obiektDetailsFields = new CompositeField(
.....
new TextField('City', _t('ForumRole.CITY', 'City')),
new SimpleImageField('Avatar', 'Zdjecie')
);
$fieldset = new FieldSet(
$obiektDetailsFields
);
return $fieldset;
}
}
?>
No one has an idea?
I'm so desperate :/
EDIT
When I change function getObiekt and I give a specific ID
function getObiekt() {
$obj = DataObject::get_by_id("Obiekt", 47);
return $obj;
}
My function is not able to ID
function getObiekt(){
$obiekt = Director::urlParams();
if(isset($obiekt['ID']))
return DataObject::get_by_id("Obiekt",(int)$obiekt['ID']);
else
return false;
}
Any idea?
SOLVED
to function EditObiektForm()
need add $fields->push(new ReadonlyField("ID"));
function EditObiektForm() {
$member = $this->getObiekt();
$fields = singleton('Obiekt')->getObiektFields();
$fields->push(new ReadonlyField("ID"));
$form = new Form($this, 'EditObiektForm', $fields,
new FieldSet(new FormAction("dosave", _t('ForumMemberProfile.SAVECHANGES','Save changes')))
);
$form->loadDataFrom($member);
return $form;
}