Jump to content

Use case for $input->whitelist and $session->variable ?


Doc
 Share

Recommended Posts

Hello,

When do you choose to use $input->whitelist($key, $value) rather than $session->myvar (with myvar = 3 for example) ?

The documentation uses the example of the MarkupPagerNav module :

"An example is the MarkupPagerNav plugin module, which provides an easy way for you to have pagination. Lets say that you used it to paginate search engine results. [...]" (from https://processwire.com/api/variables/input/)

But If I don't have pagination, but some variables to store for each member of my website, do I have any interest to store them with whitelist rather than within sessions ? 

Thanks

Link to comment
Share on other sites

$input->whitelist does not store values. It does just mark $input variables of the current request, so they can be appended to (pagination) links as ?my_data=xyz variables, which on the next request can be read again. If non of those links is clicked the values are gone. The most prominent use case is preserving any user filter values while going through pages of results. Having the values in the url also makes sure you can send that url to your peer and he or she can open it as well. 

Anything you don't want the user to see/modify you'd use the session.

  • Like 9
Link to comment
Share on other sites

  • 6 months later...
On 2/3/2017 at 2:33 PM, LostKobrakai said:

$input->whitelist does not store values

I didn't know that. It's obvious when you do, but when you don't...

I thought it was stored, like in $session or something.

It's been tripping me up for ages - using a delayed/deferred output strategy, things need to be called at different times.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...