Yii Framework Forum: CDbHttpSession - setSessionItem(id,key,val)? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CDbHttpSession - setSessionItem(id,key,val)? Rate Topic: -----

#1 User is offline   Deepak Pradhan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 209
  • Joined: 01-May 09
  • Location:Charlotte, NC

Posted 12 March 2010 - 06:55 PM

I am planing to use the following method to set a session key. Is there better/preferred way?
      public function setSessionItem($id,$key,$val) {
        $expire=time()+$this->getTimeout();
        $db=$this->getDbConnection();
        $sql="SELECT id FROM {$this->sessionTableName} WHERE id=:id";
        if($db->createCommand($sql)->bindValue(':id',$id)->queryScalar()===false)
            $sql="INSERT INTO {$this->sessionTableName} (id, $key, expire) VALUES (:id, :val, $expire)";
        else 
            $sql="UPDATE {$this->sessionTableName} SET $key=:$val, expire=$expire WHERE id = :id";
        $db->createCommand($sql)->bindValue(':id',$id)->bindValue(':val',$val)->execute();
        return true;
    }

0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 March 2010 - 07:08 PM

I don't understand. What is the additional key for? What are you trying to do?
0

#3 User is offline   Deepak Pradhan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 209
  • Joined: 01-May 09
  • Location:Charlotte, NC

Posted 12 March 2010 - 07:10 PM

View PostY!!, on 12 March 2010 - 07:08 PM, said:

I don't understand. What is the additional key for? What are you trying to do?


Good question, my session table has additional columns, broker, token, regen_sid etc. And they get updated at different point of time as well.
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 March 2010 - 07:21 PM

Okay I see. I think it's fine the way you did. However did you thought about adding the info to CWebUser instead of CHttpSession? Just a hint, maybe you really need session in this case, I don't know your application =)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users