Hello. There is a table of car brands and a table of their models (one-to-many relationship). I want to make it so that in the grid of marks there was a field "Models" and in it we say, separated by commas, all the related models of this brand. How to crank it? Where can I generate this line and give it to "eat" its grid?

    1 answer 1

    Something like this. If I understand your question correctly

    'columns' => array (

    ... array( 'name' => 'Модели', 'value' => join(', ', array_map(function($item){ return $item->title; }, $data->models)) ), ... ), 
    • @VasyOk, thanks) Works. I’ve found another method: ... 'value' => '$ data-> getModelsById ()', ... Method getModelsById (): $ criteria = new CDbCriteria; $ criteria-> select = '*'; $ criteria-> condition = 'id_mark =: id_mark'; $ criteria-> params = array (': id_mark' => $ this-> id); $ models = CarModel :: model () -> findAll ($ criteria); $ arr = CHtml :: listData ($ models, 'id', 'name'); return implode (",", $ arr); - Ray