In my controller I have model operations that can return empty results. I've setup the view to display the results using a foreach loop. But if the model opertion is empty and returns no results then the foreach loop is breaking in my view.
This is the operation:
$match3 = $this->Draw->Match-> find('all',array('conditions'=>array('Match.draw_id'=>$id, 'Match.round_id'=> 1, 'Match.match_position' => 3)));
What do I need to add to the model operation to return null? Or is null the best way to handle this?
If there is no data then I don't want anything displayed.
I did try this but got an undefined index error:
if (!$match3) return null; else return $match3;
Is there a best practice when it comes to handling empty model operations?
Much appreciated. -Paul