Saturday, August 27, 2011

Re: Saving a session variable deletes another variable

On Aug 26, 9:23 pm, 8vius <lmd...@gmail.com> wrote:
> I'll just link to the question I made on SO
>
> http://stackoverflow.com/questions/7208354/cakephp-saving-one-session...

Whew! That sure is a lot of code to read through when we're only
dealing with a simple write of data to your Session.

I will answer your question in this group rather than on your SO
thread as this is the dedicated support group for CakePHP (although it
helkps that the code is formatted on SO).

I had a quick look and pulled out the part I think is linked to the
problem

if($this->Session->read('NetworkData')) {
$networkData = $this->Session->read('NetworkData');
$this->Session->delete('NetworkData');

if($networkData['TwitterData']) {
$networkData['TwitterData']['fonyker_id'] = $fonyker['Fonyker']
['id'];
if($this->TwitterData->save($networkData)) {
$this->Session->write('TwitterData',
$networkData['TwitterData']);
}
} else if($networkData['FacebookData']) {
$networkData['FacebookData']['fonyker_id'] = $fonyker['Fonyker']
['id'];
if($this->FacebookData->save($networkData)) {
$this->Session->write('FacebookData',
$networkData['FacebookData']);
}
}
}

Why are you deleting the session? Why not just overwrite the
neccessary part with the new values?

Because you delete all data first then run an if ... else ... you're
only saving one of your networks, leaving the other blank, even if it
previously had data.

HTH, Paul

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: