I have a codeigniter app and in my model, I always return true or false for all functions, and if I have data that needs to be passed, I also set a property that contains my data.
The only trouble is, in my controller, if I have to call 3 or 4 methods in my model, the code gets really repetitive.
If ( $this->my_model->functionA() )
{
$localvar = $this->my_model->data();
}
else
{
show_error("Error A");
}
If ( $this->my_model->functionB() )
{
$localvar = $this->my_model->data();
}
else
{
show_error("Error B");
}
If ( $this->my_model->functionC() )
{
$localvar = $this->my_model->data();
}
else
{
show_error("Error C");
}
I'm wondering if i change the logic so that the functions don't return true, but return the data instead... does it simplify things alot? I think I'd still need code like this:
If (! $this->my_model->functionA() )
{
show_error("Error A");
}
else
{
$localvar = $this->my_model->data();
}
Or is there a way I can combine my $localvar assignment statement with the if statement?
Is there a better way to do this?