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

Display search result


Go to End


3 Posts   698 Views

Avatar
Bagzli

Community Member, 71 Posts

23 February 2015 at 12:35pm

Hello,

I'm trying to understand how to display search results. I'm basically allowing the user to enter name of a player and then we will display information about that player.

Here is what I have:

private static $allowed_actions = array('ADLResultForm');

    public function ADLResultForm() {
        $fields = new FieldList (
            new TextField('Summoner')
        );
        $actions = new FieldList(
            new FormAction('seekPlayer', 'Search')
        );
        $form = new Form($this, 'ADLResultForm', $fields, $actions, $requiredFields);
        $requiredFields = new RequiredFields(array('Summoner'));
        $form->Fields()->dataFieldByName('Summoner')->addExtraClass('Summoner');
        return $form;
    }


function seekPlayer($data, $form, $request) {
        if(checkBadCharacters($data)){
            $summoners = ADLPlayer::get()->filter('SummonerTag', $data['Summoner']);
            $total = $summoners->Count();

            $list = new ArrayList();
            foreach($summoners as $summoner){
                $list-push(new ArrayData(array(
                'SummonerTag' => $summoner->SummonerTag,
                'Rating'=> $summoner->Rating,
                'MVPCount'=> $summoner->MVPCount,
                'GamesWon'=> $summoner->GamesWon,
                'GamesLost'=> $summoner->GamesLost,
                'LastPlayed'=> $summoner->LastPlayed
                )));
            }

            return $list;
        }
    }

I'm not fully understanding how this works. How do I grab the search results and throw them back to my page to be displayed, I don't understand how to pass the data without having to use sessions.

Avatar
Sphere

Community Member, 46 Posts

23 February 2015 at 12:37pm

Could you also attach the template you're using for the search(result) page?

Rough guess: add a template that's rendered and loops the results maybe?

Avatar
Bagzli

Community Member, 71 Posts

23 February 2015 at 12:59pm

Well that is part of it, I don't understand how to grab and process this. Is what I wrote correct? Will that code pass the list to the template? If so how then do I call it from the template and loop it, how do I access the data inside the array?