Getting and Setting Extended User Attributes (from a select menu)

Permalink
I have configured a number of custom user attributes in the Dashboard interface. Most are just text and work fine. I am able to programmatically set and get attribute values in a single page controller with no problems like this:
$ui = UserInfo::getByID($_SESSION[uID]);
   $_SESSION[temp][billing_city] = $ui->getUserCity();
   $_SESSION[temp][firstname] = $ui->getUserFirstname();
// and am able to set like this
   $ui->setAttribute('mailing_address', $_SESSION[temp][billing_address]);
   $ui->setAttribute('firstname', $_SESSION[temp][firstname]);


However, I have another attribute for Cell Provider (so we can write scripts to text/SMS users). This is a pull down <select> menu. It works fine on the Dashboard, of course.

But when I try and retrieve the value, or set the value programmatically, I get the white screen of death (corrupted SESSION arry, I believe). Like this:

$ui = UserInfo::getByID($_SESSION[uID]);
//white screen of death on next page load
$_SESSION[temp][cell_provider] = $ui->getUserCellProvider();
//white screen of death on next page load
$ui->setAttribute('cell_provider', $_SESSION[temp][cell_provider]);


Short of hacking with machete and manually retrieving and and inserting values with MYSQL, how can I elegantly accomplish what seems like it should be a trivial task?

 
setsail replied on at Permalink Reply
Ok, don't really know why, but figured out a work around. The problem is that if you sent a $_SESSION variable directly from a getAttribute call which is not a simple text value, but an extended attribute, the entire session is corrupted resulting in a white screen of death (no output, entire site just "disappears", every page, white screen only. Delete cookies, and it all comes back).

However, if you use getAttribute to first set a variable, then process that variable in any harmless way, it then works to set it to the session, like this:

$cell_provider = $ui->getUserCellProvider();
$_SESSION[temp][cell_provider] = ucwords($cell_provider);
JohntheFish replied on at Permalink Reply
JohntheFish
Its probably because the attribute values you were writing to the $_SESSION were objects and not simple values or arrays.

The processing you apply then automatically stringifies the object.

It may still give problems for attribute objects that do not stringify automatically.
setsail replied on at Permalink Reply
Thanks John. Is there a more elegant way to 'stringify' the incoming object value?
JohntheFish replied on at Permalink Reply
JohntheFish
The problem you will find is that having stringified it to the session, you won't be able to re-create it as an attribute.

For attributes that return objects, you need to get the attribute ID as an integer and then subsequently use the attribute ID to re-load the attribute for a later request.

It may be simpler to apply such a strategy across any and all attributes.

If you don't need to re-create the attribute, maybe you could get and store the display value.

If you are open to a completely different approach, this is the sort of mixing and manipulating of little bits of data that Magic Data and its various extensions can be good for. You would need to write a 'send SMS' symbol, but I suspect much of the rest could be done without any php.