I´m trying now for days saving data in a session to use for view contextual filter etc.
The user should select something (1,2,3,4) from a dropdown, saved in a post variable and write into session.
I tried several methods, but none is working.
$tempstore = \Drupal::service('user.private_tempstore')->get('mymodule_name');
$tempstore->set('my_variable_name', $some_data);
from another post, put in a module ending in an
"Fatal error: Call to a member function getSession() on null in /usr/www/users/smplce/nordisch/core/modules/user/src/PrivateTempStore.php on line 210"
Putting this in a module:
$_SESSION['area_session']['area'] = "test";
Is not causing an error, but trying to output in page.html.twig like this:
{{ area_session.area }}
It's doing nothing.
Please help me, I´m not really a programmer but want to solve this problem.
Thanks in advance!
In Drupal 7, you would access GET, POST, SERVER and COOKIE variables using the PHP super-globals $_GET, $_POST, $_SERVER and $_COOKIE.
Examples: -> Drupal 7:
$query = $_GET['q']; // query string param
$myparam = $_POST['myparam']; // form param
$request_method = $_SERVER['REQUEST_METHOD']; // server variable
$mycookie = $_COOKIE['mycookie']; // cookie
In Drupal 8, you need to use the Symfony Request object.
->Drupal 8:
$query = \Drupal::request()->query->get('q'); // query string param
$name = \Drupal::request()->request->get('name'); // form param
$request_method = \Drupal::request()->server->get('REQUEST_METHOD'); // server variable
$mycookie = \Drupal::request()->cookies->get('mycookie'); // cookie