I want to echo a div only once in a Clistview, the items are order by status, so, i want to print status 1 -> all the items, and then status 2 -> all the items with that status, I tried viewData, but I dont know how to change the value of the flag.
INDEX VIEW:
<div class="modal-body">
<?php
$activos_flag = 1;
$inactivos_flag = 1;
?>
<?php
$this->widget('zii.widgets.grid.CListView', array(
'id'=>'incs',
'summaryText'=>'',
'dataProvider'=>$dataProviderInc,
'itemView'=>'_incidencias',
'viewData'=> array('activo'=> $activos_flag,'inactivo'=>$inactivos_flag),
));
?>
</div>
_INCIDENCIAS VIEW:
<?php
if ($data->activo == 1 and $data->incidencia_estado == 1){
echo ('<label class="incidencias">ACTIVOS</label>');
$data->activo = 0;
}
if ($data->inactivo == 1 and $data->incidencia_estado == 0){
echo ('<label class="incidencias">INACTIVOS</label>');
$data->inactivo = 0;
}
?>
You need to get the value not from the array $data
($data->inactivo
) but directly from a variable $inactivo
. But in any case, at each iteration, the value of these variables will again be equal to 1
. In this case, you can use the following approach:
Before widget declaration:
Yii::app()->params['activos_flag']=1;
Yii::app()->params['inactivos_flag']=1;
and in parial view:
if ( Yii::app()->params['activos_flag'] == 1 ){
echo ('<label class="incidencias">ACTIVOS</label>');
Yii::app()->params['activos_flag'] = 0;
}
if ( Yii::app()->params['inactivos_flag'] == 1 ){
echo ('<label class="incidencias">INACTIVOS</label>');
Yii::app()->params['inactivos_flag'] = 0;
}