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

Session exists after Session::destroy("SessionName")


Go to End


11 Posts   3025 Views

Avatar
Bagzli

Community Member, 71 Posts

27 February 2015 at 11:27am

Hey again,

Please understand that I lack knowledge in syntax to achieve what you are saying. Having said that, your part about posting does not makes sense to me at moment because here is the flow:

Here is my current logic:

1. User enters Joe
2. User clicks search
3. Request is posted to the server and envokes setSummoner method
4. SetSummoner method creates a session and saves the user input into the session
5. SetSummoner method redirects the page back to adl-look-up
6. adl-look-up template checks if session is set
7. If session is set, invoke a method getSummoner and display the data.

Here is what I understand that you are suggesting:
1. User enters Joe
2. User clicks search
3. Request is posted to the server and envokes setSummoner method
4. SetSummoner looks up in the database for the ID of the user
5. SetSummoner posts this ID back to the adl-look-up page
6. adl-look-up page calls a method that will get the data based on the ID and then displays it in the template.

My questions:
1. Is my assumption correct?
2. How does getSummoner posts back to the page and saves the data? What does code for that looks like? Will this be a URL parameter now?

I hope I was able to explain myself better this time. Words can be hard lol

Avatar
therussdotcom

Community Member, 13 Posts

27 February 2015 at 11:37am

Hey, no problem!

1. User enters Joe [YES]
2. User clicks search [YES]
3. Request is posted to the server and envokes setSummoner method [YES]
4. SetSummoner looks up in the database for the ID of the user [YES]
5. SetSummoner posts this ID back to the adl-look-up page [NO]

* Not really, there's no need. In your form you do one POST only.
* That action can make a DB query _and_ load your results in one go.

6. adl-look-up page calls a method that will get the data based on the ID and then displays it in the template. [YES]

My questions:
1. Is my assumption correct? Yes, pretty much :-)
2. How does getSummoner posts back to the page and saves the data? What does code for that looks like? Will this be a URL parameter now?

* I haven't seen any getSummoner() method - this is a new requirement! :-P
* What data are you trying to save?
* If you need to perform subsequent operations, there should be no-need for further POSTs, sessions or anything like that. If you have a DataList (You should do, I assume tha's how the results list is generated) and you're always on the same controller, you can re-use the result-set and "query it" using SS_List::find() as I illustrated before, without needing to do another (expensive) DB lookup.

If you're still stuck after this - you could grant me read-only permission to your GIT repo (assuming you're using GIT and it's public - BitBucket or GitHub?), I can pull your code and have a look - I'd need some sort of DB dump too.

Avatar
Bagzli

Community Member, 71 Posts

1 March 2015 at 5:24am

I solved the issue using the following solution:

function setPlayer($data, $form) {
        if($this->checkBadCharacters($data)){
            if(trim($data['Summoner']) == true){
                Session::set("SummonerSearch", trim($data['Summoner']));
            }
        }
        return $this->redirectBack();
    }

    function searchCheck(){
        if($test = Session::get("SummonerSearch")){
            return TRUE;
        }
        else{
            return FALSE;
        }
    }

    function showPlayer(){
        $Name = Session::get("SummonerSearch");
        $player = ADLPlayer::get()->filter('SummonerTag', $Name)->First();
        $playerTag = $player->SummonerTag;
        Session::clear("SummonerSearch");
        return new ArrayData(array("Text" => $playerTag));
    }

My template then calls:

<% if searchCheck() %>
        $showPlayer.Text
    <% end_if %>

Go to Top