Show Concatenated Values In One Gridview Line

Hi,

I have three tables (article, colorsets, colors). colors just defines different color-values, colorsets ist used to define a set of colors an article may have. colors an colorsets have an 1:n relation

colors

1 blue

2 red

3 green

4 yellow

colorsets

a 1

a 2

a 4

b 2

b 3

article

ball b

car a

This means that article ‘ball’ may have colors ‘red, green’ and car may have ‘blue, red, yellow’.

Now my question. I like to have a grid view which shows the articles with all possible colors and not only the colorset-id.

ball red,green

car blue, red, yellow

Also in a form to edit one article I want to have a dropdownbox for the colorsets, where the colors are displayed and not only the colorset id.

I think my problem is to get values from an ActiveRecords into one string variable.

Can anybody help me?

Create a method in your model like "getColors" that will return a string of the available colors. Then use that method to display your colors.

Model:




public function getColors() {

    //place code to retrieve color values for $this

    return $colors;

}



View:




echo $model->colors;



It’s magic!

Sorry for my late response - I had to take an unplanned trip.

Many thanks for your tip laqrhead!. This pointed me in the right direction to solve my problem. As a newbie, sometimes I don’t see how simple things can be :rolleyes:

get value code in Controller if you use active form




$model->attributes=$_POST['/*your controller name*/'];

$value = $model->color; //$model->your variable name in the model is same dropdownbox



Can you post your some code the view, controller and model file code?