Tenho uma CGridView que mostra idpedido, idcliente, total, etc. Gostaria que no campo idcliente mostrasse o Nome do Cliente. Consegui fazer nas ListView e nas Combobox, mas não achei nada ate agora que mostre como se faz na CGridView
Page 1 of 1
Cgridview Com Chave Estrangeira
#2
Posted 15 January 2013 - 05:40 AM
Se você fez todas as ligações corretas na criação do banco, no seu model irá ter as ligações tipo assim:
Então na GridView você utiliza assim:
Espero ter ajudado
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'maquina0' => array(self::BELONGS_TO, 'Maquinas', 'maquina'),
);
}
Então na GridView você utiliza assim:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'metas-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'name' => 'maquina',
'value' => '$data->maquina0->nome',
),
array(
'header' => 'Opções',
'class' => 'CButtonColumn',
),
),
));
?>
Espero ter ajudado
Adrian Lucas
A fé em Deus nos faz crer no incrível,
ver o invisível e realizar o impossível.
A fé em Deus nos faz crer no incrível,
ver o invisível e realizar o impossível.
Share this topic:
Page 1 of 1

Help












