通过管理生成器创建新记录时发送电子邮件

发布于 2024-09-07 00:38:16 字数 1450 浏览 3 评论 0原文

我使用 symfony admin 生成器创建了一个用于运动员管理的 Web 应用程序。最后一个客户的要求之一是添加一项功能,以便在数据库中插入具有相同号码的运动员时通知用户并向管理员发送电子邮件。到目前为止,运动员表的列号有一个唯一的约束,但客户希望运动员无论如何都可以插入。

为了实现这一目标,我试图扩展编辑/新操作以实现客户要求。

这是代码:

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。

I had used the symfony admin generator to create an web application for athletes management. One of the last client's requirement was to add a feature to notice the user and send an e-mail to the administrators when an athlete with the same number is inserted on the database. Until now, the column number of the Athlete table had a unique constraint but the client desires that the athlete can by inserted anyway.

To accomplish that, I was trying to extend the the edit / new actions in order to implement the client requirements.

Here is the code:

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);
    }

Here is my problem: when I execute the edit action, I only want to check for a duplicate athlete number when the HTTP is POST but it seems that never is. I had already sent some exceptions to the output to verify which type is HTTP Request and it seems it is always GET.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烏雲後面有陽光 2024-09-14 00:38:16

您将遇到的问题是,当您在“编辑”页面上单击“保存”时,信息不会发布到编辑操作,而是发布到称为更新的操作。

查看缓存中的 actions.class.php 文件,您就会看到它。

The problem you will be having is that when you hit save on the Edit page the information isn't posted to the edit action, it is posted to an action called update.

Have a look at the actions.class.php file in the cache and you will see it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文