Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] Save dataObject in frontend

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

Page: 1
Go to End
Author Topic: 856 Views
  • Craftnet
    Avatar
    Community Member
    58 Posts

    [SOLVED] Save dataObject in frontend Link to this post

    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

  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: [SOLVED] Save dataObject in frontend Link to this post

    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

    Attached Files
  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: [SOLVED] Save dataObject in frontend Link to this post

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

  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: [SOLVED] Save dataObject in frontend Link to this post

    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;
    }


    then all good.

    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;

    }

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