jds43 Posted August 5, 2021 Share Posted August 5, 2021 Hello, I'm wanting to allow the user to remove a key from their session, that had been created by previous form input, by clicking a link with a query string. The condition runs, but I'm getting the following error with no changes to the session. PHP Notice: Indirect modification of overloaded property ProcessWire\Session::$itinerary has no effect I imagine the session is protected from accessing this way. Does anyone have any suggestions? foreach($session->itinerary as $key => $value) { echo "<li class='uk-text-capitalize uk-flex uk-flex-row uk-flex-middle'> <a href='$page->url?$key=true' data-unset='$key' data-uk-icon='icon: minus-circle'></a> The ".str_replace("-", " ", $key)." </li>"; if(isset($_GET[$key])){ if(is_array($session->itinerary)) { // destroy a single element of an array unset($session->itinerary[$key]); $session->redirect($page->url); } } } Link to comment Share on other sites More sharing options...
Zeka Posted August 5, 2021 Share Posted August 5, 2021 https://processwire.com/api/ref/session/remove/ 1 Link to comment Share on other sites More sharing options...
jds43 Posted August 5, 2021 Author Share Posted August 5, 2021 Thanks @Zeka No luck with the following change. The session persists. Any ideas? if(isset($_GET[$key])){ if(is_array($session->itinerary)) { // destroy a single element of an array $session->remove($key); $session->redirect($page->url); } } Link to comment Share on other sites More sharing options...
Robin S Posted August 5, 2021 Share Posted August 5, 2021 You have to first get the "itinerary" array as a variable distinct from the $session->itinerary overloaded property, modify it as needed, and then set it back to $session->itinerary. if(isset($_GET[$key])){ $itinerary = $session->itinerary; if(is_array($itinerary)) { // destroy a single element of an array unset($itinerary[$key]); $session->itinerary = $itinerary; $session->redirect($page->url); } } 2 2 Link to comment Share on other sites More sharing options...
jds43 Posted August 6, 2021 Author Share Posted August 6, 2021 @Robin S you are my hero! It works perfectly. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now