一旦用户点击某些内容,如何更新现有记录?

时间:2011-08-18 01:31:17

标签: php symfony-1.4

我正在使用symfony 1.4原则,我的项目遇到了问题。如何更新symfony中的现有记录?

这是我的情景。在我的项目的后端应用程序中,当用户将他/她的预订表单发送到后端时(我的项目是会议室预订系统),管理员(处理后端应用程序)可以收到信息/记录。如果他/她的请求得到批准,管理员将通过电子邮件通知他/她我是否可以=)。问题是我不知道,因为我是symfony的新手,如果管理员点击已批准的链接,如果从“待处理请求”(从请求批准)更改为已批准,或者如果单击“拒绝”按钮,则反之亦然。

我也有代码它可以发送邮件(除了更新记录之外,这段代码有效,以防万一你可能会改变我的代码) 有人能帮我吗?你能给我一些提示吗?一些PHP代码或symfony代码?

apps/backend/modules/reservation/actions/actions.class.php

<?php

require_once dirname(__FILE__).'/../lib/reservationGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/reservationGeneratorHelper.class.php';

class reservationActions extends autoReservationActions
{
     public function executeListApprove(sfWebRequest $request)
  {

    $reservation = $this->getRoute()->getObject();
    $reservation->approve(true);


    $mailer = $this->getMailer()->composeAndSend(
      'supervisor@teleserv.local',
      $reservation->getEmail(),
      'Request Approval',
      '
          Good Day. Hello This is Martin from the tech dept.
       We have received your request.You can now use the 
       conference room due to your requested schedule. If 
       you have questions of your approval or your request,
       Please contact me within 24 hrs. Thank you.

       Martin
       Junior Programmer
       '
      );

      $this->getUser()->setFlash('notice', 'Sent mail approval:');
      $this->redirect('reservation/index');

  }

     public function executeListDisapprove(sfWebRequest $request)
  {
    $reservation = $this->getRoute()->getObject();
    $reservation->Disapprove(true);

    $mailer = $this->getMailer()->composeAndSend(
      'supervisor@teleserv.local',
       $reservation->getEmail(),
      'Request Disapproval',
      '
          Good Day. Hello This is Martin from the tech dept.
       We have received your request.Unfortunately, We
       can\'t approve your request due: 
        1.Conflicts with the schedule. 
        2.Invalid request information.
       If you have questions of your disapproval or your
       request, Please contact me within 24 hrs. Thank you

       Martin
       Junior Programmer'
      );



      $this->getUser()->setFlash('notice', 'Sent mail disapproval:');
      $this->redirect('reservation/index');

  }  
}

1 个答案:

答案 0 :(得分:0)

马丁!

您应该在更改后保存对象。

$reservation->save();

提示:

  • 不要混用控制器层和视图层,
  • 使用配置(app_yml)

    $reservation = $this->getRoute()->getObject();
    $reservation->approve(true);
    $reservation->save();
    
    $mailer = $this->getMailer()->composeAndSend(
      sfConfig::get('app_email_sender'),
      $reservation->getEmail(),
      'Request Approval',
      $this->getPartial('email_approve_body')
    );
    
    $this->getUser()->setFlash('notice', 'Sent mail approval:');
    $this->redirect('reservation/index');