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:
-
A person is logging in and his id is being send via URL
-
The person is selecting events he is interested in from the cGridView (checkbox column)
-
Writing some comment
4.Pressing send button , and the following create action is being triggered:
public function actionXcreate()
{
$model=new Person_Event;
if(isset($_POST['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);
}
$this->redirect(array('site/success'));
}
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 http://www.yiiframework.com/wiki/353/working-with-cgridview-in-admin-panel/
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?