symfony 1.4-doctrine save()方法:如何识别成功
有人能告诉我如何知道symfony 1.4-doctrine save()方法:如何识别成功,doctrine,symfony1,symfony-1.4,Doctrine,Symfony1,Symfony 1.4,有人能告诉我如何知道save()方法是否成功。我试图找出它是否返回true/false,但它返回null 例如: $contact_obj->save(); 如何知道它是有效的?如果你使用条令,请尝试trySave(): 您可以通过$contact_obj->getId()函数进行检查,成功后将返回插入的id abstract class Doctrine_Record { ... /** * tries to save the object and all
save()
方法是否成功。我试图找出它是否返回true/false,但它返回null
例如:
$contact_obj->save();
如何知道它是有效的?如果你使用条令,请尝试
trySave()
:
您可以通过$contact_obj->getId()函数进行检查,成功后将返回插入的id
abstract class Doctrine_Record {
...
/**
* tries to save the object and all its related components.
* In contrast to Doctrine_Record::save(), this method does not
* throw an exception when validation fails but returns TRUE on
* success or FALSE on failure.
*
* @param Doctrine_Connection $conn optional connection parameter
* @return TRUE if the record was saved sucessfully without errors, FALSE otherwise.
*/
public function trySave(Doctrine_Connection $conn = null) {
try {
$this->save($conn);
return true;
} catch (Doctrine_Validator_Exception $ignored) {
return false;
}
}
}