I have 3 models: Person , Event and Person_event (a connection table which has person_id and event_id)
In the view of every Event I show a CgridView of the people who were added to that same Event.
I’m able to show the grid of the people , but obviously I want to show only the people for that same event.
I’v changed the search function in the model so that it will get a ‘condition’ and I’v managed to set it by hand (for example: show me only the people of event_id 34)
What I can’t do is to pass the event’s id from the url (which is being passed for the view page) to the condition. I’v tried 4-5 methods which I found on the forum but none worked. Can it be because I’m using a Person’s grid in vent’s view?
public function actionList($eventId)
{
$personEventFilter = new Person_Event('search');
if (isset($_GET['Person_Event']))
$personEventFilter->attributes = $_GET['Person_event'];
$personEventFilter->event_id = $eventId;
// ...
}
This way, you can just treat the event ID as a standard searchable field; you don’t need any special processing or to pass additional parameters into the search() method.
Double quotes allow interpolation, which means for any variable defined in a double quote its value would be used.
For instance “event_id=$id” is same as ‘event_id=34’, however your earlier string with single quote did not allow interpolation hence it was taken as ‘event_id=$id’.