【发布时间】:2014-07-03 12:44:39
【问题描述】:
我正在使用 Symfony 和 FosRestBundle 开发 API。
在我的 ApiController 中,我想在特定文件中记录所有异常:api.log
这是我的代码示例:
public function getUserAction($param){
if(is_int($param)){
$user = $this->getDoctrine()->getRepository('ProjectBundle:Account')->findOneById($param);
}
else{
$user = $this->getDoctrine()->getRepository('ProjectBundle:Account')->findOneByUsername($param);
}
if(!is_object($user)){
return "User Not Found";
}
return $user;
}
我需要在哪里捕获和记录异常?在if(!is_object($user)){ 或当我检索$user 时?以及如何在我的文件 api.log 中保存和记录异常?
谢谢!
【问题讨论】: