[support] Unserializing Data for Use in a View

Shai Gluskin shai at content2zero.com
Thu Sep 2 20:23:54 UTC 2010


I'm creating a view of ubercart order products. I got the necessary data to
be accessible to Views using Table Wizard (http://drupal.org/project/tw).

The product attribute info is stored serialized in the "data" field on the
uc_order_products table. Here is an example of the raw serialized data:

a:5:{s:6:"kit_id";s:3:"570";s:6:"module";s:14:"uc_product_kit";s:10:"attributes";a:2:{s:9:"Attending";a:1:{i:0;s:26:"Jane
> Doe, John Doe";}s:4:"Note";a:1:{i:0;s:45:"We are friends of Eric Smith and
> Sandy
> Smith";}}s:9:"shippable";s:1:"0";s:9:"unique_id";s:23:"4c7d632a8090c7.95333579";}


I have no problem printing it out like above.

Unserialized it looks like this:

Array
(
[kit_id] => 570
[module] => uc_product_kit
[attributes] => Array
(
[Attending] => Array
(
[0] => Jane Doe, John Doe
)

[Note] => Array
(
[0] => We are friends of Eric Smith and Sandy Smith
)

)

[shippable] => 0
[unique_id] => 4c7d632a8090c7.95333579
)

I want to print out: Jane Doe, John Doe

Here is what views-view-field.tpl.php has to say:

// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp
$
 /**
  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  *
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  *
  * When fetching output from the $row, this construct should be used:
  * $data = $row->{$field->field_alias}
  *
  * The above will guarantee that you'll always get the correct data,
  * regardless of any changes in the aliasing that might happen if
  * the view is modified.
  */

This is what I'm putting in views-view-field.tpl.php:

$data = unserialize($output);
print $data['Attending'][0];

Nothing gets returned.

What am I doing wrong?

thanks,

Shai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20100902/5ea0e32d/attachment.html 


More information about the support mailing list