Passing Session Object by reference
Posted: Sun Jan 11, 2009 1:47 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
So I have the following code:
Where the updateLocation method takes a second parameter by reference... and in the method:
it repopulates the objects data ('by reference') and I was thinking that it would modify the values, but it doesn't - since its an object in the session I have to log out, and back in for it to show up as changed.. any ideas as to why?
Thanks in advance!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
So I have the following code:
Code: Select all
$authenticatedUser = unserialize($_SESSION['authenticatedUser']);
$locationDS = new LocationDataSource();
$locationDS->updateLocation($_POST, $authenticatedUser->location);Code: Select all
public function updateLocation($data, &$locationObj = null) {
// Confirm that the object being updated is of the correct type, if provided
if($locationObj != null && !is_a($locationObj, 'Location')) {
return false;
}
$sql = "UPDATE $this->table " .
"SET add1 = '". $data['add1'] ."', " .
"add2 = '". $data['add2'] ."', " .
"city = '". $data['city'] ."', " .
"state_id = ". $data['state_id'] .", " .
"zip = '". $data['zip'] ."' " .
"WHERE id = " . (($locationObj != null) ? $locationObj->id : $data['id']);
$result = $this->db->query($sql);
if(mysql_affected_rows($this->db->conn)) {
if($locationObj != null) {
$locationObj->populate($data);
}
return true;
}
else {
return false;
}
}Thanks in advance!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: