[eluser]rhopek[/eluser]
I have a function in a controller as follows:
Code:
function show($event_id)
{
$this->load->model('volunteers_model');
$data['records'] = $this->volunteers_model->getVols($event_id);
$this->load->view('volunteers_show', $data);
}
In my model, I have:
Code:
function getVols($event_id)
{
$this->db->select('*');
$this->db->from('volunteers');
$this->db->join('mapVolunteersToEvents', 'mapVolunteersToEvents.volunteers_id = volunteers.id', 'left');
$this->db->where('mapVolunteersToEvents.events_id', $event_Id);
$q = $this->db->get();
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
}
return $data;
}
The problem is that it won't always receive a value for that $event_id argument. If I pass one on the URL (like '/show/1'), everything is fine, but if I don't (/show), my view throws:
---
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Volunteers:
how()
Filename: controllers/volunteers.php
Line Number: 9
---
---
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: event_id
Filename: controllers/volunteers.php
Line Number: 11
---
What is the proper way to approach this? I've been pulling my hair out for hours and figured it was just time to suck it up and ask others. I think if I get past the first error, the second one will go away (or at least be easier to correct).
Thanks.