Having trouble with a GridView representation of a many to many relation

Hi guys,

I’m fairly new to Yii (started a couple days ago) and I’m struggling with a “simple” CGridView.

Basically, I have a table "client" and a table "product" that have a many-to-many relation between them, since a client can have multiple products, and a product can be bought by several clients. So I also got a third table holding ID_clients and ID_products.

This is how I coded it in the "client" model :


	public function relations()

	{

		return array(

			'product' => array(self::MANY_MANY, 'Product', 'product_client(ID_client, ID_product)'),

		);

	}

Now, what I would like to have, is a CGridView with :

  • columns : one to identify the client + as many columns as there are products

  • rows : CCheckBoxColumn to indicate whether the client has the product or not

Is that possible with DataProvider + GridView or do I have to extend some stuff ?

PS : this way of displaying the data would also be useful in a blog application where posts can have multiple categories/tags.

I suggest you not to use CGridView for such a work

Use a dataprovider / ClistView for the rows (client)

In the itemView you can select the product of the client and create the single checkbox.

CgridView is a really single pourpouse tool, don’t use in not-standard cases.