2011-08-18 55 views
0

我正在使用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(
     '[email protected]', 
     $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(
     '[email protected]', 
     $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'); 

    } 
} 

回答

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'); 
    
相关问题