TbDetailView Custom Attribute GetStatusName

When trying to use my model function GetStatusName

on TbDetailView

, but it doesn't work. It works correctly on TbGridView

.

Model function:

public function getStatusName()
{
    switch($this->status)
    {
        case self::STATUS_ACTIVE:
            return 'Active';
            break;
        case self::STATUS_DELETED:
            return 'Deleted';
            break;
        default:
            return 'Unknown';
            break;
    }
}

      

code:

<?php
$this->widget('bootstrap.widgets.TbDetailView',array(
    'type'=>'bordered condensed',
    'data'=>$model,
    'attributes'=>array(
        'name',
        array('name' => 'status', 'type' => 'text', 'value' => '$data->statusName'),
    ),
));
?>

      

View:

Name    John
Gender  $data->statusName

      

+3


source to share


3 answers


B CDetailView

, value

must be quoted directly without quotes. The value is not evaluated as CGridView

, so use:



array('name' => 'status', 'type' => 'text', 'value' => $model->statusName)

      

+4


source


<?php
$this->widget('bootstrap.widgets.TbDetailView',array(
   'type'=>'bordered condensed',
   'data'=>$model,
   'attributes'=>array(
       'name',
       array('name' => 'status', 'type' => 'text', 'value' => $data->statusName),
   ),
));
?>

      

or



<?php
$this->widget('bootstrap.widgets.TbDetailView',array(
   'type'=>'bordered condensed',
   'data'=>$model,
   'attributes'=>array(
       'name',
       array('name' => 'status', 'type' => 'text', 'value' => getStatusName($data->getStatusName)),
   ),
));
?>

      

edited after the comment.

+2


source


here is a small example, i found out right now how to work with formatting values:

    <?php $this -> widget('bootstrap.widgets.TbDetailView', array(
            'data' => $user,
            'type' => 'bordered striped condensed',
            'attributes' => array(
                    'name',
                    array(
                            'name' => 'birthDate',
                            'value' => Yii::app()->dateFormatter->format("dd.MM.yy", strtotime('$data->birthDate')),
                    ),
                    'code',
            ),
    ));
    ?>

      

+2


source







All Articles