我使用 symfony 管理生成器创建了一个用于运动员管理的 Web 应用程序。最后一个客户的要求之一是添加一项功能,以在数据库中插入具有相同号码的运动员时通知用户并向管理员发送电子邮件。到目前为止,Athlete 表的列号有一个唯一的约束,但客户希望运动员无论如何都可以插入。
为此,我试图扩展编辑/新操作以实现客户要求。
这是代码:
public function executeEdit(sfWebRequest $request)
{
$user = $this->getUser();
if(! $user->hasCredential('admin'))
{
$clube_id = $user->getAttribute('id');
$atleta_id = $request->getParameter('id');
$atleta = Doctrine::getTable('Atleta')->find($atleta_id);
if($clube_id != $atleta->clube_id)
$this->forward404();
}
if($request->get('post'))
{
// check if the inserted athlete BI already exists; if so, display a message to the user and send an email to the system admins
$atleta_id = $request->getParameter('id');
$atletaBIExiste = Doctrine::getTable('Atleta')->findDuplicateAthleteBI($atleta_id);
if($atletaBIExiste)
{
// display a notice message to the user
$this->getUser()->setFlash('error', 'Athlete already exists');
// send an email to the system administrator
}
}
return parent::executeEdit($request);
}
这是我的问题:当我执行编辑操作时,我只想在 HTTP 为 POST 时检查重复的运动员编号,但似乎从来没有。我已经向输出发送了一些异常来验证哪种类型是 HTTP 请求,并且它似乎总是 GET。