I need help with a CGridView, I have a view with a CGridview of my table Ciudad, each record in my table have idciudad,nombreciudad,…,redespacho. where redespacho is a integer and make reference to idciudad in same table. the cities can have or not have redespacho, but I need that the record to have redespacho, show the name of city and not show the idciudad.
Add image for that we can undestand me.
I hope understand me, sorry for my english.
If I understood U right, what U need here is relation, so in model class make one that we refer to record with ‘idciudad’ as pk. Something like:
'city' => [self::BELONGS_TO, 'Ciudad', 'redespacho']
and in GridView:
'name' => 'redespacho',
'value' => '!empty($data->city) ? $data->city->cityNameColumn : ""',
Thank you very much!! It was exactly what I needed, I had a similar idea, but I was wronng with the relation. I had this way.
'ciudades' => array(self::BELONGS_TO, 'Ciudad', 'idciudad'),// no work for me
again thank you very much.