Cgridview Multicomment

I’m not sure what is the way to do this , so here I ask:

I have a Person model and Event model , and a connection table Person_Event.

The interface that I got now works in the following way:

  1. A person is logging in and his id is being send via URL

  2. The person is selecting events he is interested in from the cGridView (checkbox column)

  3. Writing some comment

4.Pressing send button , and the following create action is being triggered:

public function actionXcreate()


		$model=new Person_Event;



			foreach ($_POST['selectedIds'] as $eventId)


				$pmodel=new Person_Event;

				$pmodel->person_id=$this->_person->id; 	//the id of the person who is logged in		

				$pmodel->attributes=$_POST['Person_Event'];	//the comment			

				$pmodel->event_id = $eventId;		//all the events he checked in the grid		

				if (!$pmodel->save()) print_r($pmodel->errors);				




So far , all is logical and simple. However , what I end up is that the comment the person wrote is being duplicated to every person_event row in the DB.

I want to put a text box in each row of the grid , and the commnet that will be written there will go to the specific event.

Now , I found this topic

which is kind of helpful , BUT:

I already have a foreach in the action , the one that matches the person’s id with the event’s id , so how can I put another individual comment for each combo?


Get comment with selectedid

For example

$_POST[‘comment’.selectedid] like this

Then you can read in controller :)


Ok , 2 question:

  1. I need the comment and the id as well , it looks like here I’m passing only the comment of the selected id

  2. How do I split them with "as" in order to put those 2 in the right places?

What I mean is: I need to pass both the id and the comment from the grid view to the event_id and event_comment.

How can I do it with the as loop?