Cdetailview And Serialized Data

I have two tables. t(Requests), t(steps)

t(steps) has two columns. id, name

t(Requests.steps) contains a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"5";}

the "1","2","5" are IDs in t(steps)

1=>PreMod

2=>Apply

3=>Test

4=>Backout

5=>Commit

In CDetailView, I want to be able to show

Steps: PreMod, Apply, Commit

How do I write the column array for Steps?


$this->widget("zii.widgets.CDetailView', array(

  'data'=>$model,

  'attributes' => array(

    'id',

    'approver',

    'abstract',

    array(

       'label'=>'MOP',

       'value'=>(Mop::model()->find("id=:id", array(':id"=>$model->mop))->mopID),

    ),

    array(

       'label'=>'Steps',

       'value'=>(Steps::model()->find("id=:id", array(':id"=>unserialize($model->steps))->name),

    ),

   ),

);

This isn’t doing what I thought it would do or I am just trying to do everything in one step.


'value'=>(Steps::model()->find("id=:id", array(':id"=>unserialize($model->steps))->name)

Any takers?

I have figured out a way to get the FIRST value of the ‘unserialized’ array to print out the name


'value'=>Steps::model()->findByPk( unserialize( $model->steps ))->name,

This just displays the first result in the array of [font="Courier New"]unserialize( $model->steps )[/font]

Steps: Pre-Mod

If I use


Steps::model()->findAllByPk( unserialize( $model->steps ) )

an array is returned with an array count of 3.

But if I use


'value'=>Steps::model()->findAllByPk( unserialize( $model->steps ))->name,

NULL is returned

[font="Courier New"]unserialize( $model->steps )[/font] contains

[font="Courier New"]Array([/font]

[font="Courier New"] [0] => 1[/font]

[font="Courier New"] [1] => 2[/font]

[font="Courier New"] [2] => 4[/font]

[font="Courier New"])[/font]

[font="Arial"]where 1, 2, 4 = id for Steps[/font]

I realized that maybe I was trying to do too much on one line so I solved this by doing the following.

Within my t(Requests) model I added the following function:


public function showSteps( $steps ) {

	$tmp = unserialize( $steps );

	$txt = '';

	$ctr = 0;


	$data = Steps::model()->findAllByPk( $tmp );

	$total = count( $data );

	foreach( $data as $value ) {

		$ctr++;

		if( $ctr < $total ) {

			$txt .= $value['name'] . ', ';

		} else {

			$txt.= $value['name'];

		}

	}

	return $txt;

}

In my t(Requests)/view – CListView row


'value'=>Requests::model()->showSteps( $model->steps ),