RJ45
(Almgandi300)
April 24, 2013, 7:03am
1
Hi, I have a many to many relation and I can show all related data in one column. Like in Label address I show 3 addresses. What I want now is to have 3 Labels created dynamically and show each address separated.
How I get Address now:
public function getAddressName()
{
$names = array();
foreach($this->addresses as $address) {
$names[] = $address->name.";";
}
return implode("\n", $names);
}
Is this?
public function getAddressLabels()
{
$arrLabels = array();
foreach($this->addresses as $address)
{
$arrLabels[] = CHtml::label($address);
}
return $arrLabels;
}
RJ45
(Almgandi300)
April 24, 2013, 7:55am
3
I think i wasn’t clear enough.
CDetailView looks like this atm.
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
array(
'label'=>'Address',
'type'=>'raw',
'value'=>$model->addressName,
),
),
)); ?>
The output looks like this:
Id: 1
Address: address1, address2, address3,
I want it to look like that:
Id: 1
Address: address1
Address: address2
Address: address3
A simple method could be substitute last line of your getAddressName() method with:
return implode("<br />", $names);
but last left label will be one for all address values.
RJ45
(Almgandi300)
April 24, 2013, 8:42am
5
Mhh yea, but that give me the output:
Address: address1
address2
address3
I think something like dynamic row generation is needed for each address.
If this is possible?
You could extract array attributes and populate separately.
I mean:
$arrAttributes = array( 'id' );
$arrLabels = array();
foreach($this->addresses as $address)
{
$arrLabels[] = array( 'label' => 'Address', 'value' => $address);
}
$arrAttributes = $arrAttributes + $arrLabels;
$this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=> $arrAttributes
),
));
RJ45
(Almgandi300)
April 24, 2013, 9:10am
7
Thank you very much.
That is exactly what I was looking for.