DBにサブスクリプションを実装しています。メールは一意である必要があるため、データベースにUNIQUEインデックスがあります。私は私のページの初期化にこのコードを持っています:
$f = $p->add('MVCForm');
$f->setModel('Account',array('name','surname','email'));
$f->elements['Save']->setLabel('Subscribe');
if($f->isSubmitted())
{
try
{
$f->update();
//More useful code to execute when all is ok :)
}
catch(Exception_ValidityCheck $v)
{
//Handles validity constraint from the model
$f->getElement($v->getField())->displayFieldError($v->getMessage());
}
catch(SQLException $se)
{
//If I'm here there is a problem with the db/query or a duplicate email
}
}
の唯一の情報SQLException
はフォーマットされたHTMLメッセージですが、これはエラーが重複したエントリからのものであるかどうかを検出する唯一の方法ですか?