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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

[solved] Data Not being saved


Go to End


4 Posts   496 Views

Avatar
Bagzli

Community Member, 71 Posts

16 February 2015 at 11:22am

Edited: 16/02/2015 11:30am

Hello,

I have a php class as follows:

<?php
class ADLScoreManager extends Page {
}
class ADLScoreManager_Controller extends Page_Controller {
   private static $allowed_actions = array('GameResultForm');

    public function GameResultForm() {

        $gameDate = new DateField('GameDate');
        $gameDate->setConfig('showcalendar', true);
        $gameDate->setConfig('dateformat', 'dd/MM/YYYY');
        $fields = new FieldList (
            $gameDate,
            new OptionsetField(
               $name = "WinningTeam",
               $title = "Who won?",
               $source = array(
                  "1" => "Team 1",
                  "2" => "Team 2"
               ),
               $value = "1"
            ),
            new OptionsetField(
               $name = "TeamOneMVP",
               $title = "Who is the MVP for Team 1?",
               $source = array(
                  "1" => "Player A",
                  "2" => "Player B",
                  "3" => "Player C",
                  "4" => "Player D",
                  "5" => "Player E"
               ),
               $value = "1"
            ),
            new TextField('PlayerA'),
            new TextField('PlayerB'),
            new TextField('PlayerC'),
            new TextField('PlayerD'),
            new TextField('PlayerE'),
            new OptionsetField(
               $name = "TeamTwoMVP",
               $title = "Who is the MVP for Team 2?",
               $source = array(
                  "1" => "Player F",
                  "2" => "Player G",
                  "3" => "Player H",
                  "4" => "Player I",
                  "5" => "Player J"
               ),
               $value = "1"
            ),
            new TextField('PlayerF'),
            new TextField('PlayerG'),
            new TextField('PlayerH'),
            new TextField('PlayerI'),
            new TextField('PlayerJ')
        );
        $actions = new FieldList(
            new FormAction('SaveNewGame', 'Save New Group')
        );
        return new Form($this, '', $fields, $actions);
    }

    public function SaveNewGame($data, $form){
        $adlPlayerOne = ADLPlayer::create();
        $adlPlayerOne->SummonerTag = 'ThisIsATest';
        $adlPlayerOne->write();
    }

    public function GetPlayers(){
        $holder = ADLPlayer::get()->First();
        return $holder;
    }
}

I also have a data model as follows:

<?php
class ADLPlayer extends DataModel {
    private static $db = array(
        'SummonerTag' => 'Varchar',
        'Rating' => 'Decimal',
        'GamesWon' => 'Int',
        'GamesLost' => 'Int',
        'LastPlayed' => 'Date'
    );
}
class ADLPlayer_Controller extends Page_Controller {
}

And a .ss page as follows:
<div id="BrowserPoll">
    <h2>Browser Poll</h2>
    $GameResultForm
    1
    <% loop $GetPlayers() %>
        $SummonerTag
    <% end_loop %>
    2
</div>

Right now there is no validation, because I am just testing this. I am trying to click the submit button, a class for ADLPlayer will be created and then summoner name will be written to that class. Next time I visit the same page, I will have all ADLPlayers listed below. However this is not working and I cannot figure out why. Any help is most appreciated.

Edit:
I have also looked in phpMyAdmin and could not find my ADL tables anywhere. I did run /dev/build and even ?flush=1 on the page.

Avatar
camfindlay

Forum Moderator, 267 Posts

16 February 2015 at 11:35am

Edited: 16/02/2015 11:36am

"DataModel" should be "DataObject" and you also don't need a controller for a DataObject.

Avatar
Bagzli

Community Member, 71 Posts

16 February 2015 at 11:40am

Edited: 16/02/2015 11:41am

Thank you camfindlay!

I have corrected it to DataObject and re-ran /dev/build but I'm still not getting any results displayed. I have checked phpMyAdmin and the tables are now there, hurray! however they are empty, which means my method to write the object does not works.

Avatar
Bagzli

Community Member, 71 Posts

16 February 2015 at 11:49am

I found the problem, thank you! Now it works as it is intended.