Reputation: 1291
The following function in MerryParent model returns $merry_parent_id or empty string if it is not able to find any. If it is going to return an empty string, i want to stop that and display an error message in the model itself instead of creating an if then else stmt in controller and displaying the error message there. How can I do that?
I don't know on how to display error msgs in model function. In controller I know that I can use $this->Session->setFlash('my error msg'). But that doesn't work here.
By the way, i'm trying to abide by 'fat model thin controller approach'. :)
class MerryParent extends AppModel{
//relationships are displayed here
//form field validations are displayed here
function getMerryParentId($email){
$merry_parent_id=$this->field('id',array('MerryParent.email'=>$email));
return $merry_parent_id;
/*instead as return $merry_parent_id, I want
if ($merry_parent_id!='')
return $merry_parent_id;
else
//display error message here.
}
}
thank you.
Upvotes: 0
Views: 130
Reputation: 29121
You shouldn't be displaying errors via the model. If you want to display something just for testing purposes, you can debug() it in the model...etc, but in general, you should use the normal MVC structure, and use the model to retrieve the data, use the controller to process it, and the view to display it.
The "Fat model / Skinny controller" thing is great to follow as a guideline, but when you follow it too far and stop following the more-important MVC structure, it's not a good thing. It's not meant to be "Fat model / Empty controller". :)
Upvotes: 3