Reputation: 505
I have a problem how to show value of array in CGridView? I have this code in /user/admin.php
array(
'type'=>'raw',
'name'=>'jabatan',
'header'=>'Jabatan',
'filter'=>array('0'=>'Kepala Subdirektorat','1'=>'Kepala Seksi','2'=>'Staf'),
'value'=>$data->jabatan
),
I have set 'value'=>$data->value
but it shows the index of array, ex. '1'. I wanted to show the value of array, ex. 'Staf'.
So, how to show its value? Anybody can help me fix this? Thanks a lot
Upvotes: 1
Views: 551
Reputation: 505
Oh thanks a lot to @Kunal Dethe for his advice, I've solved it
I just create a function on model User.php
public function getNama_jabatan() {
$listjabatan = array('0'=>'Kepala Subdirektorat', '1'=>'Kepala Seksi', '2'=>'Staf');
$namajabatan = $listjabatan[$this->jabatan];
return $namajabatan;
}
then, I call the function on /user/admin.php 'value'=>'$data->nama_jabatan'
Thanks a lot.....
Upvotes: 2
Reputation: 1274
In Model Class -
public static function getJabatanName($jabatan == null) {
$value = '';
if($jabatan) {
if($jabatan == 0)
$value = 'Kepala Subdirektorat';
elseif($jabatan == 1)
$value = 'Kepala Seksi';
elseif($jabatan == 2)
$value = 'Staf';
}
return $value;
}
And in admin.php -
array(
'type'=>'raw',
'name'=>'jabatan',
'header'=>'Jabatan',
'filter'=>array('0'=>'Kepala Subdirektorat','1'=>'Kepala Seksi','2'=>'Staf'),
'value'=>MODEL_NAME::getJabatanName($data->jabatan)
),
Upvotes: 1