2016-09-09 2 views
0

데이터베이스의 테이블에서 요소를 가져와 한 조건에 따라 Gridview에 표시하려고하면 성공하지 못합니다. 여기 (Yii) CGridView의 조건에 따라 데이터베이스 값 바꾸기

이있는 gridview의 내 코드입니다 :

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'invoice-grid', 
'dataProvider' => $model->search(), 
'filter' => $model, 
'columns' => array(  

    'number', 
    'recipient_user_id', 
    'recipientName', 
    'recipientCompany', 
    'type' => function($data, $row) { 
        if ($data->type == 1) { return "Hello"; } 
        if ($data->type == 2) { return "Bye"; } 
        if ($data->type == 3) { return "Good"; } 
        if ($data->type == 4) { return "Milk"; } 
       }, 
    'periodFrom', 

    array(
     'class' => 'CButtonColumn', 
     'template'=>'{view}', 
    ), 
), 

)); ?>

아직 작동하지 않습니다. 다른 아이디어가 있습니까?

+0

죄송합니다. 드디어 내 실수를 발견했다. – stfsngue

답변

0

죄송합니다. 드디어 내 실수를 발견했다. 일반적으로해야 할 일 :

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'invoice-grid', 
'dataProvider' => $model->search(), 
'filter' => $model, 
'columns' => array(  

    'number', 
    'recipient_user_id', 
    'recipientName', 
    'recipientCompany', 

     array(
       'name'=>'type', 
       'value'=>function($data, $row) { 
        if ($data->type == 1) { return "Hello"; } 
        if ($data->type == 2) { return "Bye"; } 
        if ($data->type == 3) { return "Good"; } 
        if ($data->type == 4) { return "Milk"; } 
       }, 

     ), 

    'periodFrom', 

    array(
     'class' => 'CButtonColumn', 
     'template'=>'{view}', 
    ), 
), 

))); ?>

관련 문제