I'm just wondering if you see any ways I could simplify the following code without making it too difficult for a newbie to understand what I'm trying to do:
if (trim($this->uri->segment(5)) == 1) {
if ( $this->my_model->functionA($this->uri->segment(8),$this->uri->segment(4)) )
{
$data['light'] = $this->my_model->data();
}
else
{
show_error($this->my_model->errormessage());
}
}
elseif (trim($this->uri->segment(5)) == 0) {
if ( $this->my_model->functionB($this->uri->segment(8),$this->uri->segment(4)) )
{
$data['light'] = $this->my_model->data();
}
else
{
show_error($this->my_model->errormessage());
}
}
elseif (trim($this->uri->segment(5)) == 2) {
if ( $this->my_model->functionC($this->uri->segment(8),$this->uri->segment(4)) )
{
$data['light'] = $this->my_model->data();
}
else
{
show_error($this->my_model->errormessage());
}
}
I guess I could use a switch statement but i would still need to check the results of each function call. Would it still be beneficial to use switch? if so, can you explain why?
Any suggestions would be appreciated. thanks.