PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 27, 2022

[FIXED] yii and session variables

 January 27, 2022     php, session, yii     No comments   

Issue

Currently working within Yii framework.
I am trying to set a temp array of 16 numbers and refresh the page. However; I ran into a small issue and was trying to find an alternative way of solving this. Currently I was trying to save the array as an attribute in the model, but now I know that can not be done. What I need to do is set a temp variable, check for that temp variable, handle the page accordingly, and then delete the temp variable. I have been reading about Session variables, and it seems like that would be my first choice.

My Questions:

1) Is Session the way to go/Is there a better way?

2) Is Yii using a session, and if so, will I break that?

if(1 && 2){ 3) What is the proper way to instantiate an array in a session and delete it?; }


Solution

You can use the setState(), hasState() and getState() methods of the CWebUser class.

//to set the random values
Yii::app()->user->setState('random_key', $theValues);

//to check if the key exists
if (Yii::app()->user->hasState('random_key')) { echo true; }

//to get the random values back
$my_values = Yii::app()->user->getState('random_key');

Here's the link the the CWebUser class reference



Answered By - Oladapo Omonayajo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing